Git cheat sheet
The Git commands you'll use every day, each explained in one line. Practice all of them in the interactive tutorial.
Start
git clone <url> | Download a project and its history |
git status | What changed? What's staged? |
git log --oneline | History, one commit per line |
Save changes
git diff | Show unstaged changes |
git add <file> | Stage a file (. for everything) |
git commit -m "msg" | Save a snapshot |
git commit --amend | Redo the last commit |
Branches
git switch -c <name> | Create a branch and switch to it |
git switch <name> | Switch branches |
git merge <branch> | Bring a branch into yours |
git branch -d <name> | Delete a merged branch |
Share
git fetch | Download news, change nothing |
git pull | Fetch + merge |
git push | Upload your commits |
git push -u origin <branch> | Push a new branch |
Undo
git restore <file> | Discard uncommitted changes |
git restore --staged <file> | Unstage a file |
git revert <commit> | Undo a pushed commit safely |
git reset --soft HEAD~1 | Undo the last commit, keep changes |
git reflog | Find lost commits |
git stash / git stash pop | Put work aside / bring it back |