← Back🌿
Git Command Reference
Searchable cheat sheet of 100+ essential Git commands with examples.
Setup
git initInitialize a new local repository
git clone <url>Clone a repository from remote
git config --global user.name 'Name'Set global username
git config --global user.email 'email'Set global email
Basics
git statusShow working tree status
git add <file>Stage a specific file
git add .Stage all changes
git commit -m 'msg'Commit staged changes
git diffShow unstaged changes
git diff --stagedShow staged changes
git log --onelineCompact commit history
Branching
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 branch -d <branch>Delete a branch
git switch <branch>Switch branches (modern syntax)
Merging
git merge <branch>Merge a branch into current
git rebase <branch>Rebase current branch onto another
git cherry-pick <hash>Apply a specific commit
git merge --abortAbort a merge in progress
Remote
git remote add origin <url>Add a remote repository
git push origin <branch>Push branch to remote
git pullFetch and merge from remote
git fetchFetch from remote without merging
git push --tagsPush all tags to remote
Undo
git reset HEAD <file>Unstage a file
git checkout -- <file>Discard changes in working directory
git revert <hash>Revert a commit (safe)
git reset --hard HEAD~1Delete last commit (destructive)
git clean -fdRemove untracked files/dirs
Stash
git stashStash current changes
git stash popApply most recent stash
git stash listList all stashes
git stash dropDelete most recent stash