β All cheat sheets
π§
Git Cheat Sheet
A quick-reference Git cheat sheet covering the everyday commands: commit, branch, merge, push, pull, stash, and undo.
Setup & Config
git initCreate a new empty Git repository in the current directory.git clone <url>Copy a remote repository, including its full history, to your machine.git config --global user.name "Your Name"Set the author name used on all your commits.git config --global user.email "you@example.com"Set the author email used on all your commits.git config --listShow all current Git configuration values.Staging & Committing
git statusShow staged, unstaged, and untracked files.git add <file>Stage a specific file for the next commit.git add .Stage all changes in the current directory and below.git commit -m "message"Commit the staged changes with a message.git commit -am "message"Stage all tracked, modified files and commit in one step (skips new files).Branching & Merging
git branchList local branches; the current one is marked with an asterisk.git branch <name>Create a new branch without switching to it.git checkout -b <name>Create a new branch and switch to it.git switch <name>Switch to an existing branch (modern alternative to checkout).git merge <name>Merge the named branch into the current branch.git branch -d <name>Delete a branch that has already been merged.Remotes
git remote -vList configured remote repositories and their URLs.git pushUpload local commits to the tracked remote branch.git push -u origin <branch>Push a branch and set it to track origin for future pushes.git pullFetch changes from the remote and merge them into the current branch.git fetchDownload remote changes without merging them into your work.Inspecting History
git log --onelineShow commit history as a compact one-line-per-commit list.git diffShow unstaged changes compared to the last commit.git diff --stagedShow changes that are staged for the next commit.git show <commit>Show the details and diff of a specific commit.git blame <file>Show who last changed each line of a file and when.Undoing Changes
git restore <file>Discard unstaged changes in a file (working tree changes are lost).git restore --staged <file>Unstage a file while keeping its changes in the working tree.git reset --soft <commit>Move HEAD back but keep changes staged.git reset --hard <commit>Reset to a commit and discard all changes β destructive, work is lost.git revert <commit>Create a new commit that undoes a previous commit (safe for shared history).git checkout -- <file>Discard local changes to a file (older syntax; changes are lost).Stashing
git stashTemporarily shelve uncommitted changes and clean the working tree.git stash push -m "message"Stash changes with a descriptive label.git stash listList all stashed change sets.git stash popReapply the most recent stash and remove it from the list.git stash dropDelete the most recent stash without applying it.Tags
git tagList all tags in the repository.git tag <name>Create a lightweight tag pointing at the current commit.git tag -a <name> -m "message"Create an annotated tag with a message and metadata.git push origin <name>Push a single tag to the remote.git push --tagsPush all local tags to the remote.Useful Extras
.gitignoreList file patterns Git should never track, one per line.git cherry-pick <commit>Apply a single commit from another branch onto the current one.git rebase <branch>Reapply your commits on top of another branch for a linear history.git rebase -i <commit>Interactively reorder, squash, or edit commits β avoid on shared history.git reflogShow a log of where HEAD has been, useful for recovering lost commits.Reading is good β doing is better. Practice Git with interactive, auto-graded lessons.
Start learning Git