Git Commands Cheatsheet

Essential Git commands for version control: setup, commits, branches, merging, and remote operations.

CommandDescriptionSyntaxExampleCategory
git initInitialize a new git repositorygit init [project-name]git init my-projectSetup
git cloneClone a repositorygit clone <url>git clone https://github.com/user/repo.gitSetup
git configSet git configurationgit config --global user.name "Name"git config --global user.email "user@example.com"Setup
git statusCheck repository statusgit statusgit statusLocal
git addStage files for commitgit add <files>git add . git add file.jsLocal
git commitCommit staged changesgit commit -m "message"git commit -m "Add new feature"Local
git logView commit historygit log [options]git log --oneline --graphHistory
git diffShow changes between commitsgit diff [branch1] [branch2]git diff main developHistory
git restoreRestore working tree filesgit restore <file>git restore file.jsLocal
git resetReset changesgit reset [--hard|--soft] [HEAD~n]git reset --hard HEAD~1History
git revertCreate a new commit reverting changesgit revert <commit>git revert abc123History
git branchManage branchesgit branch [branch-name]git branch feature/new-featureBranches
git checkoutSwitch branchesgit checkout <branch>git checkout developBranches
git switchSwitch branches (new syntax)git switch <branch>git switch mainBranches
git mergeMerge branchesgit merge <branch>git merge feature/new-featureBranches
git rebaseRebase commits onto another branchgit rebase <branch>git rebase mainAdvanced
git stashSave uncommitted changesgit stash [save "message"]git stash save "WIP"Local
git stash popRestore stashed changesgit stash popgit stash popLocal
git pushPush commits to remotegit push <remote> <branch>git push origin mainRemote
git pullFetch and merge remote changesgit pull <remote> <branch>git pull origin mainRemote
git fetchFetch remote changesgit fetch <remote>git fetch originRemote
git remoteManage remote repositoriesgit remote [add|remove|set-url]git remote add upstream https://github.com/upstream/repo.gitRemote
git tagCreate version tagsgit tag <tag-name>git tag v1.0.0Advanced
git cherry-pickApply specific commitsgit cherry-pick <commit>git cherry-pick abc123Advanced
git cleanRemove untracked filesgit clean -fdgit clean -fdLocal