Leaderboard ad · 728×90

Git Cheatsheet

Common Git commands by category. Copy commands with one click and filter via search.

61 entries matched

Configuration & init5

git config --global user.name "Your Name"Set global username
git config --global user.email "[email protected]"Set global email
git config --global --listList global configuration
git config --global init.defaultBranch mainSet the default branch name
git initInitialize a new repository here

Daily changes13

git statusShow working tree status
git status -sShow status in short format
git add <file>Stage a file
git add .Stage all changes
git commit -m "message"Commit staged changes
git commit -am "message"Stage tracked files and commit
git commit --amendAmend the last commit
git diffShow unstaged changes
git diff --stagedShow staged changes
git rm <file>Remove a file and stage the deletion
git mv <old> <new>Move or rename a file
git restore <file>Discard working tree changes
git restore --staged <file>Unstage a file, keep changes

Branches11

git branchList local branches
git branch <name>Create a new branch
git checkout <branch>Switch to a branch
git checkout -b <branch>Create and switch to a branch
git switch <branch>Switch to a branch (modern)
git switch -c <branch>Create and switch to a branch (modern)
git merge <branch>Merge a branch into the current one
git merge --abortAbort a merge in progress
git rebase <branch>Rebase the current branch onto another
git branch -d <branch>Delete a merged branch
git branch -D <branch>Force delete a branch

Remotes11

git clone <url>Clone a remote repository
git remote add origin <url>Add a remote named origin
git remote -vList remotes
git fetchFetch remote updates without merging
git fetch --pruneFetch and prune deleted remote branches
git pullFetch and merge remote changes
git pull --rebaseFetch and rebase remote changes
git push origin <branch>Push a branch to the remote
git push -u origin <branch>Push and set upstream tracking
git push --force-with-leaseForce push with a safety check
git push origin --delete <branch>Delete a remote branch

History & undo13

git logShow commit history
git log --oneline --graphCompact graphical history
git show <commit>Show details of a commit
git blame <file>Show who last changed each line
git reflogShow the local reference log
git reset --soft HEAD~1Undo the last commit, keep changes
git reset --hard HEAD~1Undo the last commit, discard changes
git reset --hard <commit>Hard reset to a specific commit
git revert <commit>Revert a commit with a new commit
git stashStash current changes
git stash listList stashes
git stash popApply and drop the latest stash
git cherry-pick <commit>Apply a single commit to the current branch

Tags8

git tagList all tags
git tag v1.0.0Create a lightweight tag
git tag -a v1.0.0 -m "release"Create an annotated tag
git show v1.0.0Show tag details
git push origin v1.0.0Push a tag to the remote
git push --tagsPush all tags
git tag -d v1.0.0Delete a local tag
git push origin :refs/tags/v1.0.0Delete a remote tag
In-content ad · responsive