Git Cheat Sheet
A high-density reference guide for the essential Git commands covered in this professional curriculum.
🛠️ Setup & Config
| Command | Result |
|---|---|
git init | Initialize a new local repository. |
git clone <url> | Download a copy of a remote repository. |
git config --global user.name "Your Name" | Set your global commit identity username. |
git config --global user.email "you@email.com" | Set your global commit identity email. |
📸 Basic Snapshots
| Command | Result |
|---|---|
git add <file> | Stage a file for the next commit. |
git commit -m "msg" | Snapshot your staged changes with a message. |
git status | Show the current state of files (Modified/Staged). |
git diff | View unstaged changes in your files. |
🌿 Branching & Merging
| Command | Result |
|---|---|
git branch | List all local branches. |
git switch -c <name> | Create and switch to a new branch. |
git merge <name> | Merge the specified branch into your current one. |
git rebase <base> | Replay your commits on top of another base. |
☁️ Collaboration (Remotes)
| Command | Result |
|---|---|
git remote add origin <url> | Link your local repo to a remote server. |
git push origin <branch> | Upload your local commits to the server. |
git pull origin <branch> | Download AND merge changes from the server. |
git fetch origin | Download changes from the server (does NOT merge). |
🔄 Undoing & Fixing
| Command | Result |
|---|---|
git reset --hard <hash> | Roll back to a commit and delete all local work. |
git revert <hash> | Create a new commit that undoes an old one. |
git cherry-pick <hash> | Surgically apply one specific commit to your branch. |
git stash | Temporarily save uncommitted work to switch focus. |
🔍 Code Forensics
| Command | Result |
|---|---|
git log --oneline | View short history of commits. |
git blame <file> | See who modified every line in a file and when. |
git show <hash> | View the content changes of a specific commit. |
git bisect | Use binary search to find the commit that broke code. |
[!TIP] Pro Tip: Use
git help <command>(e.g.,git help rebase) to open the local manual page for any Git tool in your browser!