Git Tutorial
Version control essentials — commits, branches, merges, and rebasing.
Git tracks changes so you can collaborate and undo mistakes. This tutorial covers daily commands.
First commit
git init
git add README.md
git commit -m "Add readme"
Branching
git switch -c feature/login
# ... edit files ...
git add .
git commit -m "Implement login"
git switch main
git merge feature/login
Inspecting history
git log --oneline --graph
git diff main..feature/login
git show <commit>
Rebasing for a clean history
git switch feature/login
git rebase main # replay your commits on top of main
| Command | Use it to |
|---|---|
git status |
see what changed |
git stash |
temporarily shelve work |
git reset |
undo staged changes |
git revert |
safely undo a published commit |
Prefer
git revertovergit resetfor commits others have already pulled.
Fix a messy last commit
git add forgotten.txt
git commit --amend -m "Better message"