Git Tutorial

Version control essentials — commits, branches, merges, and rebasing.

1 min read 134 words Updated Mar 5, 2026

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 revert over git reset for commits others have already pulled.

Fix a messy last commit

git add forgotten.txt
git commit --amend -m "Better message"