Git Cheat Sheet: Essential Git Commands

x32x01
  • by x32x01 ||
If you work on Python, Data Science, AI, or any software project, you don't need to memorize dozens of Git commands. Start with the core workflow below and build from there.

🚀 1. Start a Git Project​

Initialize Git and check the current state of your project:
Bash:
git init
git status
What they do:
  • git init initializes a new Git repository.
  • git status shows which files have changed and what Git is currently tracking.



💾 2. Save Your Changes​

After making changes, stage and commit them:
Bash:
git add .
git commit -m "Add data cleaning"
Think of the workflow this way:
  • git add → Stage your changes.
  • git commit → Save a snapshot of those changes in the project's history.
A commit gives you a clear point you can refer back to later.



☁️ 3. Connect Your Project to GitHub​

To connect your local repository to a GitHub repository and push your code:
Bash:
git remote add origin
git branch -M main
git push -u origin main
After the push completes, your local project is available in the remote GitHub repository.
Remember: Git and GitHub are not the same thing. Git handles version control, while GitHub provides hosting and collaboration features for Git repositories.

🌿 4. Create a Feature Branch​

When working on a new feature, you can create a separate branch instead of making changes directly on main:
Bash:
git switch -c feature/dashboard
After finishing the feature:
Bash:
git add .
git commit -m "Add dashboard"
git switch main
git merge feature/dashboard
This keeps feature development separate from the main branch until you're ready to merge it.



🔍 5. See What Changed​

These commands are useful when you want to understand the current state or history of your project:
Bash:
git diff
git log --oneline
git status
  • git diff → Shows changes that have not been committed.
  • git log --oneline → Shows a compact version of the commit history.
  • git status → Shows the current state of your working directory and staging area.



👥 6. Work With a Remote Repository​

When collaborating with others or working across multiple devices, you'll commonly use:
Bash:
git pull
git push
  • ⬇️ git pull → Fetches changes from the remote repository and integrates them into your current branch.
  • ⬆️ git push → Uploads your local commits to the remote repository.



🎯 The Git Workflow to Remember​

You can think of the basic Git workflow as a simple cycle:
Code:
Edit
↓
git add
↓
Staging Area
↓
git commit
↓
Local Repository
↓
git push
↓
GitHub
When working with existing remote changes, git pull brings those changes back into your local project.



Git vs. GitHub​

This is one of the most common points of confusion for beginners.
GitGitHub
Version control systemPlatform for hosting and collaborating on Git repositories
Runs locally on your computerProvides a remote service for your repositories
Tracks changes and commitsHelps you share, review, and collaborate on code
📌 Don't try to memorize 50 Git commands at once.
Start with this core set:
status → add → commit → push → pull → branch → merge → diff → log
Once this workflow becomes familiar, learning more advanced Git commands becomes much easier.



Frequently Asked Questions​

------------------

What are the most important Git commands for beginners?​

Start with git status, git add, git commit, git push, git pull, git switch, git merge, git diff, and git log.

What is the difference between Git and GitHub?​

Git is a version control system used to track changes in a project. GitHub is a platform that hosts Git repositories and provides tools for collaboration, code review, and sharing.

What does git add do?​

git add stages changes so they can be included in the next commit.

What does git commit do?​

git commit saves the staged changes as a snapshot in the repository's history.

What does git pull do?​

git pull retrieves changes from a remote repository and integrates them into your current local branch.

What does git push do?​

git push sends your local commits to a remote repository such as GitHub.
 
Similar threads
x32x01
Replies
0
Views
104
x32x01
x32x01
x32x01
Replies
0
Views
95
x32x01
x32x01
x32x01
Replies
0
Views
100
x32x01
x32x01
x32x01
Replies
0
Views
97
x32x01
x32x01
x32x01
Replies
0
Views
129
x32x01
x32x01
Forum Statistics
Threads
1,080
Messages
1,085
Members
16
Latest Member
b_a_s_m_a_l_a7
Back
Top