Git Command Cheatsheet
Searchable reference for common Git commands.
34 of 34 commands
Setup
git initCreate a new empty repository in the current directory.
git clone <url>Copy an existing repository to your local machine.
git config --global user.name "name"Set the name used in your commits.
Basics
git statusShow changed, staged, and untracked files.
git add <file>Stage a file's changes for the next commit.
git add .Stage all changes in the current directory.
git commit -m "message"Record staged changes with a message.
git commit --amendEdit the most recent commit instead of creating a new one.
git diffShow unstaged changes compared to the last commit.
git diff --stagedShow staged changes compared to the last commit.
History
git logShow commit history for the current branch.
git log --oneline --graphShow a compact, graph-style commit history.
git show <commit>Show the changes introduced by a specific commit.
git blame <file>Show who last changed each line of a file.
Branching
git branchList local branches.
git branch <name>Create a new branch.
git switch <branch>Switch to an existing branch.
git switch -c <branch>Create a new branch and switch to it.
git merge <branch>Merge another branch into the current branch.
git rebase <branch>Reapply commits on top of another branch.
git branch -d <branch>Delete a local branch (only if merged).
Remote
git fetchDownload commits and branches from a remote without merging.
git pullFetch from a remote and merge into the current branch.
git pushUpload local commits to a remote branch.
git push -u origin <branch>Push a branch and set it to track the remote branch.
git remote -vList remotes and their URLs.
Undo
git reset --soft HEAD~1Undo the last commit but keep changes staged.
git reset --hard HEAD~1Undo the last commit and discard the changes entirely.
git checkout -- <file>Discard local changes to a file.
git revert <commit>Create a new commit that undoes a previous commit.
git stashTemporarily shelve uncommitted changes.
git stash popRe-apply the most recently stashed changes.
Tags
git tag <name>Create a tag at the current commit.
git tag -a <name> -m "message"Create an annotated tag with a message.