Git Cheatsheet
95+ Git commands with descriptions — searchable by keyword or category. Click Copy to grab any command.
git initSetupInitialize a new local repository.
git init <directory>SetupCreate a new repository in the specified directory.
git clone <url>SetupClone a remote repository into a new local directory.
git clone <url> <directory>SetupClone into a specific local folder name.
git clone --depth 1 <url>SetupShallow clone — only the latest commit (faster).
git clone --branch <branch> <url>SetupClone and check out a specific branch.
git config --global user.name "Name"ConfigSet the global author name for all commits.
git config --global user.email "email"ConfigSet the global author email for all commits.
git config --global core.editor vimConfigSet the default text editor for commit messages.
git config --listConfigList all config settings (global + local).
git config --global alias.st statusConfigCreate a shortcut alias (e.g. `git st` → `git status`).
git config --global pull.rebase trueConfigRebase instead of merge when pulling.
git config --global color.ui autoConfigEnable colorized output in the terminal.
git statusBasicsShow the working tree status (staged, unstaged, untracked).
git add .BasicsStage all changes in the current directory.
git add <file>BasicsStage a specific file.
git add -pBasicsInteractively stage hunks within files.
git commit -m "message"BasicsCommit staged changes with a message.
git commit --amendBasicsModify the last commit (message or staged content).
git commit --amend --no-editBasicsAmend the last commit without changing the message.
git diffBasicsShow unstaged changes relative to the index.
git diff --stagedBasicsShow staged changes ready for the next commit.
git diff <branch1>..<branch2>BasicsCompare two branches.
git rm <file>BasicsRemove a file from the working tree and index.
git mv <old> <new>BasicsMove or rename a file and stage the change.
git branchBranchingList all local branches.
git branch -aBranchingList local and remote branches.
git branch <branch>BranchingCreate a new branch at the current HEAD.
git branch -d <branch>BranchingDelete a fully merged branch.
git branch -D <branch>BranchingForce-delete a branch regardless of merge status.
git branch -m <old> <new>BranchingRename a branch.
git checkout -b <branch>BranchingCreate and check out a new branch.
git switch <branch>BranchingSwitch to an existing branch (modern syntax).
git switch -c <branch>BranchingCreate and switch to a new branch (modern syntax).
git checkout -BranchingSwitch back to the previously checked-out branch.
git merge <branch>MergingMerge the specified branch into the current branch.
git merge --no-ff <branch>MergingMerge with a merge commit, even if fast-forward is possible.
git merge --squash <branch>MergingSquash branch commits into a single staged change.
git merge --abortMergingAbort a merge in progress and return to pre-merge state.
git mergetoolMergingOpen a merge conflict resolution tool.
git remote -vRemoteList remote connections with URLs.
git remote add origin <url>RemoteAdd a new remote named "origin".
git remote remove <name>RemoteRemove a remote connection.
git remote rename <old> <new>RemoteRename a remote.
git push origin <branch>RemotePush a branch to the remote.
git push -u origin <branch>RemotePush and set upstream tracking for the branch.
git push --force-with-leaseRemoteSafe force-push: fails if remote has new commits.
git push origin --delete <branch>RemoteDelete a remote branch.
git pullRemoteFetch and merge changes from the tracking remote branch.
git pull --rebaseRemoteFetch and rebase instead of merging.
git fetchRemoteDownload remote changes without merging.
git fetch --pruneRemoteFetch and remove stale remote-tracking branches.
git stashStashSave dirty working directory to the stash stack.
git stash push -m "message"StashStash with a descriptive label.
git stash popStashApply the latest stash and remove it from the stack.
git stash apply stash@{n}StashApply a specific stash without removing it.
git stash listStashList all stashed changesets.
git stash drop stash@{n}StashDelete a specific stash entry.
git stash clearStashRemove all stash entries.
git stash branch <branch>StashCreate a new branch from the latest stash.
git logHistoryShow the full commit history.
git log --onelineHistoryCompact one-line-per-commit log.
git log --graph --oneline --allHistoryVisual branch graph with all refs.
git log -p <file>HistoryShow patch diff for each commit touching a file.
git log --author="Name"HistoryFilter commits by author.
git log --since="2 weeks ago"HistoryShow commits from the last two weeks.
git log --grep="keyword"HistorySearch commit messages for a keyword.
git blame <file>HistoryShow who last modified each line of a file.
git show <commit>HistoryShow metadata and diff for a specific commit.
git shortlog -snHistorySummarize commits by author (sorted by count).
git restore <file>UndoingDiscard unstaged changes in a file.
git restore --staged <file>UndoingUnstage a file (keep working copy changes).
git reset HEAD~1UndoingUndo the last commit, keeping changes unstaged.
git reset --soft HEAD~1UndoingUndo the last commit, keeping changes staged.
git reset --hard HEAD~1UndoingUndo the last commit and discard all changes.
git revert <commit>UndoingCreate a new commit that undoes a prior commit.
git clean -fdUndoingRemove untracked files and directories.
git clean -nUndoingDry-run clean — show what would be deleted.
git reflogUndoingShow a log of all reference updates (recover lost commits).
git rebase <branch>AdvancedRebase current branch onto another branch.
git rebase -i HEAD~3AdvancedInteractive rebase for the last 3 commits (squash, reword, etc.).
git rebase --abortAdvancedAbort an in-progress rebase.
git rebase --continueAdvancedContinue a rebase after resolving conflicts.
git cherry-pick <commit>AdvancedApply a specific commit onto the current branch.
git cherry-pick <hash1>..<hash2>AdvancedApply a range of commits onto the current branch.
git bisect startAdvancedStart a binary search to find the commit that introduced a bug.
git bisect good <commit>AdvancedMark a commit as good during bisect.
git bisect bad <commit>AdvancedMark a commit as bad during bisect.
git bisect resetAdvancedEnd the bisect session and return to original HEAD.
git worktree add <path> <branch>AdvancedCheck out a branch in a separate directory (worktree).
git worktree listAdvancedList all linked worktrees.
git tag <name>AdvancedCreate a lightweight tag at the current commit.
git tag -a <name> -m "message"AdvancedCreate an annotated tag with a message.
git push origin --tagsAdvancedPush all local tags to the remote.
git submodule add <url>AdvancedAdd an external repository as a submodule.