The Git commands you use every day, organized by workflow.
| git init | Initialize a new repo |
| git clone <url> | Clone a repository |
| git config user.name "Name" | Set name for commits |
| git config user.email "email" | Set email for commits |
| git status | Check working tree status |
| git add <file> | Stage a specific file |
| git add . | Stage all changes |
| git add -p | Stage changes interactively (patch mode) |
| git commit -m "msg" | Commit with message |
| git commit --amend | Amend last commit |
| git reset HEAD <file> | Unstage a file |
| git diff | Show unstaged changes |
| git diff --staged | Show staged changes |
| git branch | List local branches |
| git branch <name> | Create a branch |
| git checkout <branch> | Switch to branch |
| git checkout -b <name> | Create and switch to branch |
| git switch <branch> | Switch to branch (modern) |
| git switch -c <name> | Create and switch (modern) |
| git branch -d <name> | Delete branch (safe) |
| git branch -D <name> | Delete branch (force) |
| git branch -a | List all branches (incl. remote) |
| git merge <branch> | Merge branch into current |
| git rebase <branch> | Rebase current onto branch |
| git rebase --abort | Abort rebase |
| git rebase --continue | Continue rebase after resolving |
| git merge --abort | Abort merge |
| git cherry-pick <hash> | Apply a single commit |
| git remote -v | List remotes |
| git remote add origin <url> | Add a remote |
| git fetch | Fetch from remote |
| git pull | Pull (fetch + merge) |
| git pull --rebase | Pull (fetch + rebase) |
| git push | Push to remote |
| git push -u origin <branch> | Push and set upstream |
| git push --force-with-lease | Force push (safer) |
| git stash | Stash working changes |
| git stash pop | Apply and remove last stash |
| git stash apply | Apply last stash (keep it) |
| git stash list | List all stashes |
| git stash drop | Delete last stash |
| git stash -u | Stash including untracked files |
| git log | View commit history |
| git log --oneline | Compact commit history |
| git log --graph | Visual branch graph |
| git log -p | Log with diffs |
| git show <hash> | Show a specific commit |
| git blame <file> | Show who changed each line |
| git reflog | View reference log (recovery) |
| git checkout -- <file> | Discard changes in file |
| git restore <file> | Discard changes (modern) |
| git reset --soft HEAD~1 | Undo last commit, keep staged |
| git reset --mixed HEAD~1 | Undo last commit, keep unstaged |
| git reset --hard HEAD~1 | Undo last commit, discard all |
| git revert <hash> | Create a commit that undoes a commit |
| git clean -fd | Remove untracked files and dirs |