Git Commands For Developers
What is version control?
Version control lets you track changes, collaborate with others, and maintain a history of your codebase. Git is by far the most popular version control system out there - pretty much every dev team uses it.
I've been using Git since my first dev job and honestly, it took a while before things clicked. These days most of these commands are muscle memory, but I remember how confusing it all seemed at first.
The Basics
These are the commands you'll use constantly:
# Start a new repo
git init
# Stage files for commit
git add . # Stage everything
git add src/components/ # Stage a specific folder
# Commit your changes
git commit -m "add user login form"
# Check what's changed
git status
# View commit history
git log --oneline
Branching
Branches let you work on features without messing up the main codebase. I create new branches constantly.
# Create and switch to a new branch
git checkout -b feature/add-search
# or the newer way
git switch -c feature/add-search
# List all branches
git branch -a
# Switch between branches
git checkout main
git switch main
# Delete a branch (local)
git branch -d feature/add-search
# Force delete
git branch -D feature/add-search
Working with Remotes
# Clone a repo
git clone git@github.com:username/repo.git
# Push your branch
git push origin feature/add-search
# Set upstream so you can just use 'git push' next time
git push -u origin feature/add-search
# Pull latest changes
git pull origin main
# Fetch without merging (I do this a lot)
git fetch origin
Rebasing
Rebasing keeps your commit history clean. I rebase onto main before opening PRs to avoid messy merge commits.
# Rebase your branch onto main
git checkout feature/add-search
git rebase main
# Interactive rebase to squash/edit commits
git rebase -i HEAD~3
# If you mess up, abort
git rebase --abort
During interactive rebase, you can:
pick- keep the commitsquash- combine with the previous commitreword- change the commit messagedrop- remove the commit entirely
Stashing
When you need to quickly switch branches but don't want to commit half-finished work:
# Stash your changes
git stash
# Stash with a message (helpful when you have multiple stashes)
git stash push -m "wip: search component styling"
# List stashes
git stash list
# Apply the latest stash
git stash pop
# Apply a specific stash
git stash apply stash@{2}
Undoing Things
We all make mistakes. Here's how to fix them:
# Undo last commit but keep changes staged
git reset --soft HEAD~1
# Undo last commit and unstage changes
git reset HEAD~1
# Completely undo last commit (careful with this one)
git reset --hard HEAD~1
# Discard changes in a file
git checkout -- src/App.tsx
# Create a new commit that undoes a previous commit
git revert abc123
GitHub CLI
The GitHub CLI (gh) has become part of my daily workflow. It's way faster than clicking around the website.
# Create a PR
gh pr create --title "Add search feature" --body "Implements full-text search"
# List open PRs
gh pr list
# Check out a PR locally
gh pr checkout 123
# View PR in browser
gh pr view --web
# Create an issue
gh issue create --title "Bug: login fails on Safari"
# Clone a repo (shorter than the full URL)
gh repo clone owner/repo
Conventional Commits
I've started using conventional commits on most projects. Makes the git history way more readable and works nicely with automated changelogs.
git commit -m "feat: add user authentication"
git commit -m "fix: resolve login redirect loop"
git commit -m "docs: update API documentation"
git commit -m "refactor: extract validation logic"
git commit -m "chore: update dependencies"
The format is type(optional scope): description. Common types are feat, fix, docs, style, refactor, test, and chore.
Useful Aliases
I have these in my .gitconfig:
[alias]
co = checkout
br = branch
st = status
last = log -1 HEAD
undo = reset HEAD~1
amend = commit --amend --no-edit
Wrapping Up
Git has a steep learning curve but once you get comfortable with these commands, you'll wonder how you ever worked without them. When things go wrong (and they will), git reflog is your friend - it shows everything you've done and lets you recover from almost any mistake.
The official Git docs are surprisingly readable if you want to dig deeper.
© Tom Blaymire 2026. All rights reserved.
