Git & Version Control · Cheatsheet
Git Commands Cheatsheet
Common Git commands for setup, commits, branches, merges, history, stashes, and remote operations.
55 commands 8 sections
No entry matches that filter.
-
git initInitialize a new Git repository -
git clone <url>Clone a remote repository -
git config --global user.name "Name"Set your name for all repos -
git config --global user.email "email"Set your email for all repos -
git config --listShow all configuration settings
-
git statusShow working tree status -
git add <file>Stage a specific file -
git add .Stage all changes in current directory -
git add -pInteractively stage hunks -
git commit -m "message"Commit staged changes with message -
git commit --amendModify the last commit -
git reset HEAD <file>Unstage a file -
git checkout -- <file>Discard changes in working directory
-
git branchList all local branches -
git branch <name>Create a new branch -
git checkout <branch>Switch to a branch -
git checkout -b <branch>Create and switch to new branch -
git switch <branch>Switch to a branch (modern) -
git switch -c <branch>Create and switch to new branch (modern) -
git merge <branch>Merge branch into current branch -
git branch -d <branch>Delete a merged branch -
git branch -D <branch>Force delete a branch -
git branch -m <old> <new>Rename a branch
-
git remote -vList remote repositories -
git remote add origin <url>Add a remote repository -
git fetchDownload objects from remote -
git pullFetch and merge from remote -
git pull --rebaseFetch and rebase onto remote -
git pushPush commits to remote -
git push -u origin <branch>Push and set upstream tracking -
git push --force-with-leaseForce update if the remote matches expectations; background fetches can weaken the default check
-
git logShow commit history -
git log --oneline --graphCompact log with branch graph -
git log -p <file>Show changes over time for a file -
git diffShow unstaged changes -
git diff --stagedShow staged changes -
git diff <branch1>..<branch2>Compare two branches -
git show <commit>Show details of a commit -
git blame <file>Show who changed each line
-
git stashStash current changes -
git stash save "message"Stash with a description -
git stash listList all stashes -
git stash popApply and remove latest stash -
git stash applyApply latest stash without removing -
git stash dropDelete latest stash -
git stash clearDelete all stashes
-
git revert <commit>Create new commit that undoes a commit -
git reset --soft HEAD~1Undo last commit, keep changes staged -
git reset --mixed HEAD~1Undo last commit, keep changes unstaged -
git reset --hard HEAD~1Undo last commit and discard changes -
git cherry-pick <commit>Apply a specific commit to current branch -
git rebase <branch>Reapply commits on top of another branch -
git rebase -i HEAD~3Interactive rebase for last 3 commits
-
https://git-scm.com/docsGit reference: repository, branch, history, and remote commands. -
https://git-scm.com/docs/git-pushGit push: force-with-lease conditions and background-fetch limits.