Everyday Git commands and what they do. Download: CSV · JSON. Commands marked destructive can lose uncommitted work.
| Command | What it does |
|---|---|
git init | Create a new repository in the current folder |
git clone <url> | Copy a remote repository locally |
git status | Show changed and staged files |
git add <file> | Stage a file for commit |
git add -p | Stage changes interactively, hunk by hunk |
git commit -m "msg" | Commit staged changes with a message |
git commit --amend | Rewrite the most recent commit |
git log --oneline --graph | Compact commit history with branch graph |
git diff | Show unstaged changes |
git diff --staged | Show staged changes |
git branch <name> | Create a branch |
git switch <name> | Switch to a branch |
git switch -c <name> | Create and switch to a new branch |
git merge <branch> | Merge a branch into the current one |
git rebase <branch> | Replay current commits on top of another branch |
git stash | Shelve uncommitted changes |
git stash pop | Reapply the latest stash |
git restore <file> | Discard unstaged changes to a file |
git restore --staged <file> | Unstage a file |
git reset --hard HEAD | Discard all local changes (destructive) |
git revert <commit> | Create a commit that undoes another commit |
git fetch | Download remote changes without merging |
git pull --rebase | Fetch and rebase local commits on the remote |
git push -u origin <branch> | Push a branch and set its upstream |
git tag v1.0.0 | Tag the current commit |
git cherry-pick <commit> | Apply one commit onto the current branch |
git reflog | Show history of HEAD movements (recover lost commits) |
git blame <file> | Show who last changed each line |
git bisect start | Binary-search for the commit that introduced a bug |
git clean -fd | Remove untracked files and folders (destructive) |