Showing 45 of 45 commands
Install, configure identity and initialise repositories
git config --global user.name "<name>"beginnerSet the author name used on your commits
git config --global user.email "<email>"beginnerSet the author email used on your commits
git config --listbeginnerShow all current Git configuration values
git initbeginnerCreate a new empty Git repository in the current directory
git clone <url>beginnerCopy a remote repository to your machine
Track changes, stage files and record commits
git statusbeginnerShow the working tree status - staged, unstaged and untracked files
git add <file>beginnerStage changes for the next commit
git commit -m "<message>"beginnerRecord staged changes to the repository history
git diffbeginnerShow changes between working tree and the index
git rm <file>intermediateRemove a file from the working tree and stage the deletion
git mv <src> <dest>beginnerMove or rename a file and stage the change
Create, switch and manage branches
git branchbeginnerList all local branches (current marked with *)
git switch <branch>beginnerSwitch to an existing branch
git switch -c <branch>beginnerCreate a new branch and switch to it
git branch -d <branch>beginnerDelete a branch that has been merged
git branch -m <new-name>intermediateRename the current branch
Combine branches and rewrite history
git merge <branch>intermediateMerge another branch into the current branch
git rebase <branch>advancedReapply your commits on top of another branch for a linear history
git rebase -i HEAD~<n>advancedInteractively rewrite the last n commits
git cherry-pick <commit>advancedApply a specific commit from another branch
Push, pull and manage remote repositories
git remote -vbeginnerList configured remote repositories and their URLs
git remote add <name> <url>beginnerAdd a new remote repository
git fetch <remote>intermediateDownload objects and refs without merging
git pullbeginnerFetch from the remote and merge into the current branch
git pushbeginnerUpload local commits to the remote
Reset, revert and recover from mistakes
git restore <file>beginnerDiscard uncommitted changes in a file
git reset <file>beginnerUnstage a file while keeping its changes
git reset --soft HEAD~1intermediateUndo the last commit but keep changes staged
git reset --hard <commit>advancedReset the branch and working tree to a commit, discarding changes
git revert <commit>intermediateCreate a new commit that undoes a previous commit
git reflogadvancedShow a log of where HEAD has been - your safety net
Temporarily shelve work in progress
git stashintermediateSave uncommitted changes and revert to a clean tree
git stash listbeginnerList all stashed change sets
git stash popintermediateApply the most recent stash and remove it from the list
git stash applyintermediateApply a stash but keep it in the stash list
git stash dropintermediateDelete a specific stash
Browse logs, blame and inspect commits
git logbeginnerShow the commit history
git show <commit>beginnerShow the details and diff of a specific commit
git blame <file>intermediateShow who last modified each line of a file
git diff <a>..<b>intermediateCompare two commits or branches
git bisect startadvancedBinary-search commit history to find a bug-introducing commit
Every Git command you need - with flags, real-world examples, and pro tips. Search, filter by difficulty, and copy with one click.
devopslesson.com/tools/cheatsheets/git
git config --global user.name "<name>"beginnerSet the author name used on your commits
git config --global user.name "Jane Doe"💡 Use --global for all repos, or omit it to set per-repository config.
git config --global user.email "<email>"beginnerSet the author email used on your commits
git config --global user.email "jane@example.com"git config --listbeginnerShow all current Git configuration values
git config --list --show-origingit initbeginnerCreate a new empty Git repository in the current directory
git initgit clone <url>beginnerCopy a remote repository to your machine
git clone https://github.com/user/repo.gitgit statusbeginnerShow the working tree status - staged, unstaged and untracked files
git status -sgit add <file>beginnerStage changes for the next commit
git add .💡 Use git add -p to review and stage hunks one at a time.
git commit -m "<message>"beginnerRecord staged changes to the repository history
git commit -m "Add login endpoint"git diffbeginnerShow changes between working tree and the index
git diff --stagedgit rm <file>intermediateRemove a file from the working tree and stage the deletion
git rm --cached secret.envgit mv <src> <dest>beginnerMove or rename a file and stage the change
git mv app.js src/app.jsgit branchbeginnerList all local branches (current marked with *)
git branch -agit switch <branch>beginnerSwitch to an existing branch
git switch feature/login💡 git switch is the modern replacement for git checkout <branch>.
git switch -c <branch>beginnerCreate a new branch and switch to it
git switch -c feature/paymentsgit branch -d <branch>beginnerDelete a branch that has been merged
git branch -d feature/logingit branch -m <new-name>intermediateRename the current branch
git branch -m maingit merge <branch>intermediateMerge another branch into the current branch
git merge feature/logingit rebase <branch>advancedReapply your commits on top of another branch for a linear history
git rebase main💡 Never rebase commits that have been pushed and shared with others.
git rebase -i HEAD~<n>advancedInteractively rewrite the last n commits
git rebase -i HEAD~3💡 Great for squashing WIP commits before opening a pull request.
git cherry-pick <commit>advancedApply a specific commit from another branch
git cherry-pick a1b2c3dgit remote -vbeginnerList configured remote repositories and their URLs
git remote -vgit remote add <name> <url>beginnerAdd a new remote repository
git remote add origin git@github.com:user/repo.gitgit fetch <remote>intermediateDownload objects and refs without merging
git fetch origingit pullbeginnerFetch from the remote and merge into the current branch
git pull --rebase origin main💡 git pull --rebase keeps history linear and avoids noisy merge commits.
git pushbeginnerUpload local commits to the remote
git push -u origin main💡 Prefer --force-with-lease over --force to avoid overwriting teammates’ commits.
git restore <file>beginnerDiscard uncommitted changes in a file
git restore src/app.jsgit reset <file>beginnerUnstage a file while keeping its changes
git reset HEAD app.jsgit reset --soft HEAD~1intermediateUndo the last commit but keep changes staged
git reset --soft HEAD~1git reset --hard <commit>advancedReset the branch and working tree to a commit, discarding changes
git reset --hard HEAD~1💡 Destructive - --hard permanently discards uncommitted work.
git revert <commit>intermediateCreate a new commit that undoes a previous commit
git revert a1b2c3d💡 Safe for shared branches - it does not rewrite history.
git reflogadvancedShow a log of where HEAD has been - your safety net
git reflog💡 Use reflog to recover “lost” commits after a bad reset or rebase.
git stashintermediateSave uncommitted changes and revert to a clean tree
git stash push -m "wip: login form"git stash listbeginnerList all stashed change sets
git stash listgit stash popintermediateApply the most recent stash and remove it from the list
git stash popgit stash applyintermediateApply a stash but keep it in the stash list
git stash apply stash@{1}git stash dropintermediateDelete a specific stash
git stash drop stash@{0}git logbeginnerShow the commit history
git log --oneline --graph --allgit show <commit>beginnerShow the details and diff of a specific commit
git show a1b2c3dgit blame <file>intermediateShow who last modified each line of a file
git blame src/app.jsgit diff <a>..<b>intermediateCompare two commits or branches
git diff main..featuregit bisect startadvancedBinary-search commit history to find a bug-introducing commit
git bisect start && git bisect bad && git bisect good v1.0💡 A powerful way to pinpoint exactly which commit broke something.
git tagbeginnerList all tags
git tag -l "v1.*"git tag -a <name> -m "<msg>"intermediateCreate an annotated tag for a release
git tag -a v1.2.0 -m "Release 1.2.0"git push <remote> <tag>intermediatePush a tag to the remote
git push origin v1.2.0git tag -d <name>intermediateDelete a local tag
git tag -d v1.2.0