tool / 50
Git Commands
The git commands you reach for daily. From basics to lifesavers like reflog.
All local
38/38
Setup4
git init
git init
Initialize a new repository in the current directory.
git clone
git clone <url>
Clone a remote repository.
git config
git config --global user.name "Name"
Set your global username.
git config
git config --global user.email "email@example.com"
Set your global email.
Inspect6
git status
git status
Show changed files.
git diff
git diff
Show unstaged changes.
git diff
git diff --staged
Show staged changes.
git log
git log --oneline --graph --all
Compact graph of all branches.
git blame
git blame <file>
Who last touched each line.
git show
git show <commit>
Show what changed in a commit.
Stage & commit6
git add
git add <file>
Stage a file for commit.
git add
git add -p
Interactively stage hunks.
git commit
git commit -m "message"
Commit with a message.
git commit
git commit --amend
Edit the previous commit.
git restore
git restore <file>
Discard unstaged changes to a file.
git restore
git restore --staged <file>
Unstage a file.
Branches6
git branch
git branch
List local branches.
git branch
git branch -a
List all branches including remotes.
git switch
git switch <branch>
Switch to an existing branch.
git switch
git switch -c <branch>
Create and switch to a new branch.
git branch
git branch -d <branch>
Delete a merged branch.
git branch
git branch -D <branch>
Force delete an unmerged branch.
Merging4
git merge
git merge <branch>
Merge another branch into current.
git rebase
git rebase <branch>
Replay your commits on top of another branch.
git rebase
git rebase -i HEAD~5
Interactive rebase the last 5 commits.
git cherry-pick
git cherry-pick <commit>
Apply a single commit from another branch.
Remote6
git fetch
git fetch
Download remote changes without merging.
git pull
git pull
Fetch and merge remote changes.
git pull
git pull --rebase
Fetch and rebase your work on top.
git push
git push
Push commits to remote.
git push
git push -u origin <branch>
Push and set upstream tracking.
git push
git push --force-with-lease
Safer force push — refuses if remote moved.
Undo6
git stash
git stash
Stash uncommitted changes for later.
git stash
git stash pop
Reapply the latest stash.
git reset
git reset HEAD~
Undo last commit, keep changes staged.
git reset
git reset --hard HEAD~
Undo last commit AND discard changes.
git revert
git revert <commit>
Create a new commit that undoes another.
git reflog
git reflog
Show every action — your safety net.