Git Cheatsheet
Essential Git commands reference with examples for everyday use.
32 commands
Initialize repo
SetupCreate a new Git repository in the current directory.
git initClone repo
SetupCopy a remote repository to your local machine.
git clone <url>Set user name
SetupSet your name for all commits globally.
git config --global user.name "Your Name"Set user email
SetupSet your email for all commits globally.
git config --global user.email "you@example.com"Check status
BasicsShow the state of the working directory and staging area.
git statusStage all changes
BasicsStage all modified and new files for the next commit.
git add .Stage specific file
BasicsStage a specific file.
git add <file>Commit
BasicsRecord staged changes to the repository.
git commit -m "message"View log
BasicsShow a compact, visual commit history.
git log --oneline --graphShow diff
BasicsShow unstaged changes. Use --staged for staged changes.
git diffCreate branch
BranchingCreate and switch to a new branch.
git checkout -b <branch>Switch branch
BranchingSwitch to an existing branch.
git checkout <branch>List branches
BranchingList all local and remote branches.
git branch -aDelete branch
BranchingDelete a merged branch locally. Use -D to force.
git branch -d <branch>Merge branch
BranchingMerge the specified branch into the current branch.
git merge <branch>Rebase
BranchingReapply commits on top of another base branch.
git rebase <branch>Fetch
RemoteDownload changes from remote without merging.
git fetch originPull
RemoteFetch and merge changes from the remote branch.
git pull origin <branch>Push
RemoteUpload local commits to the remote repository.
git push origin <branch>Push new branch
RemotePush a new local branch and set upstream tracking.
git push -u origin <branch>Stash changes
StashTemporarily save uncommitted changes.
git stashApply stash
StashRestore the most recent stash and remove it from the list.
git stash popList stashes
StashShow all saved stashes.
git stash listUndo last commit
UndoUndo the last commit, keeping changes staged.
git reset --soft HEAD~1Discard changes
UndoDiscard unstaged changes to a specific file.
git checkout -- <file>Amend last commit
UndoModify the last commit message or add staged changes.
git commit --amend -m "new message"Revert commit
UndoCreate a new commit that undoes a previous commit.
git revert <commit-hash>Tag a commit
TagsCreate a lightweight tag at the current commit.
git tag v1.0.0Push tags
TagsPush all local tags to the remote repository.
git push origin --tagsCherry-pick
AdvancedApply a specific commit from another branch.
git cherry-pick <commit-hash>Interactive rebase
AdvancedInteractively rewrite the last 3 commits.
git rebase -i HEAD~3Bisect
AdvancedBinary search through commits to find when a bug was introduced.
git bisect start
git bisect bad
git bisect good <hash>All processing happens locally in your browser. No data is sent to any server.