Git has a reputation for being confusing, but 90% of daily work runs on about fifteen commands. Learn these and you can contribute to any project with confidence. Here they are, grouped by what you're doing.
Starting out
| Command | What it does |
|---|---|
git clone url | Copy a remote repo to your machine |
git init | Turn the current folder into a repo |
git status | See what's changed, staged, and untracked |
git config --global user.name "You" | Set your commit identity |
The daily loop
| Command | What it does |
|---|---|
git add . | Stage all changes for the next commit |
git commit -m "message" | Save staged changes with a note |
git push | Send your commits to GitHub |
git pull | Fetch and merge others' changes |
git log --oneline | See the commit history, one line each |
Branches
| Command | What it does |
|---|---|
git switch -c feature | Create and move to a new branch |
git switch main | Move back to the main branch |
git merge feature | Merge a branch into your current one |
git branch -d feature | Delete a merged branch |
The one everyone Googles:
git restore file throws away uncommitted changes to a file, and git reset --soft HEAD~1 undoes your last commit but keeps the changes. Learn these two and Git stops being scary.Undo & fix
| Command | What it does |
|---|---|
git restore file | Discard uncommitted changes to a file |
git reset --soft HEAD~1 | Undo the last commit, keep the changes |
git revert commit | Make a new commit that undoes an old one |
git stash / git stash pop | Shelve changes, then bring them back |
Keep the printable Git cheat sheet nearby
The Git & GitHub Cheat Sheet for Beginners is a clean one-pager: every command here plus a visual of the add → commit → push flow and the fixes for the mistakes beginners actually make. Instant download.
Get the cheat sheet →