Git is the version control system used by virtually every software team on the planet. It's also the tool that confuses nearly every beginner the first time they encounter it. The concepts feel abstract — "staging area," "HEAD," "detached state" — until the moment something clicks and it becomes indispensable. This guide gets you to that click as fast as possible, with just the commands you actually need.
What changed in 2026
- Git is still the universal standard. No serious alternative has replaced it; learning Git is non-negotiable for any development role.
- GitHub Copilot and AI tools write Git commands. You can ask your editor's AI assistant to explain a Git error — but you still need to understand what to confirm or reject.
- Conventional commits are mainstream. Structured commit message formats (
feat:, fix:, chore:) are used by most open-source projects and many companies.
- GitHub and GitLab now offer web-based editing for small changes, but local Git remains essential for real development.
The mental model
Git saves snapshots of your project at points you choose. Each snapshot is called a commit. Commits form a chain — a history of every change ever made.
Three key concepts:
- Working directory: the files you're editing right now.
- Staging area (index): changes you've marked to include in the next commit.
- Repository: the stored history of all commits.
Working directory → (git add) → Staging area → (git commit) → Repository
The 10 commands you need
1. Initialize or clone a repository
# Start a new repo in the current folder
git init
# Copy an existing repo from GitHub
git clone https://github.com/user/repo.git
2. Check what's changed
# See which files are modified or staged
git status
# See the actual line changes
git diff
3. Stage and commit changes
# Stage a specific file
git add filename.py
# Stage all changes in the current directory
git add .
# Commit with a message
git commit -m "Add user login feature"
4. Push and pull
# Upload your commits to GitHub
git push origin main
# Download and merge the latest changes from GitHub
git pull origin main
5. Branches
# List all branches
git branch
# Create and switch to a new branch
git checkout -b feature/user-auth
# Switch back to main
git checkout main
# Merge a branch into main
git merge feature/user-auth
A typical daily workflow
# Start the day: get latest changes
git pull origin main
# Create a branch for today's work
git checkout -b fix/login-bug
# ... make changes to files ...
# Check what you've done
git status
git diff
# Stage and commit
git add src/auth.py
git commit -m "fix: resolve null pointer in login handler"
# Push to GitHub and open a pull request
git push origin fix/login-bug
Writing good commit messages
| Bad |
Good |
stuff |
fix: prevent crash on empty username |
changes |
feat: add password reset email flow |
wip |
chore: update dependencies to latest |
fix bug |
fix: correct off-by-one error in pagination |
A good commit message answers: "if applied, this commit will…" A bad one answers: "what mood was I in?"
Fixing common mistakes
Undo the last commit (keep changes):
git reset --soft HEAD~1
Unstage a file you accidentally added:
git restore --staged filename.py
Discard local changes to a file (cannot be undone):
git restore filename.py
See the full commit history:
git log --oneline
Common mistakes
Committing directly to main. Always create a branch for any non-trivial change. Main should only receive code that's ready to ship.
Writing meaningless commit messages. "fix" or "update" are not helpful 6 months later. Be specific.
Giant commits that change everything at once. Small, focused commits make code review easier, bugs easier to find, and rollbacks safer.
Ignoring .gitignore. Never commit .env files, API keys, node_modules/, or build output. Create a .gitignore before your first commit.
# Create a .gitignore for a Python project
echo "__pycache__/
*.pyc
.env
venv/" > .gitignore
What to skip
- Memorizing
git rebase --interactive before you're comfortable with basics — it's powerful but confusing until you've made at least 100 commits.
- GUI Git clients as a crutch — they're fine, but learning the CLI commands first means you understand what the GUI is doing.
- Skipping branching because it "adds complexity" — branches are cheap (just a pointer to a commit) and save you constantly.
FAQ
What's the difference between git pull and git fetch?
git fetch downloads changes but doesn't apply them. git pull downloads and merges in one step. Start with pull; learn fetch when you need finer control.
I made a mess — how do I start over?
git stash saves your current changes safely. Then git pull origin main to get back to a clean state. Run git stash pop to restore your work.
What's a merge conflict and how do I fix it?
A merge conflict happens when two branches changed the same line differently. Git marks both versions in the file. Open the file, pick which version to keep (or combine them), then git add and git commit.
Do I need GitHub to use Git?
No. Git works entirely locally. GitHub is a hosting platform for Git repositories — useful for backup and collaboration, but not required to learn Git basics.
Where to go next
See How to use GitHub in 2026, How to become a software engineer in 2026, and How to write clean code in 2026.