
Git Crash Course: Essential Commands Every QA Must Know
Carolina Yepes March 5, 2026UpdatedMarch 5, 2026 25 min read 10 chaptersCrash Course
Master Git from scratch
Git is the backbone of modern software development. Whether you work solo or in a team, mastering Git is non‑negotiable. This crash course takes you from zero to confident — covering setup, core concepts, branching, remotes, advanced workflows, and a handy cheat sheet.
Setup — Tell Git Who You Are
Before anything else, Git needs to know who you are. It attaches your name and email to every commit you make — forever. You only do this once per machine.
git configWhat it does
--global flag means the setting applies to every project on your computer.Analogy
Scenario
Warning
--global inside a specific project folder to set a different identity just for that project — useful on shared computers.$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"
$ git config --global core.editor "code --wait"
$ git config --listuser.name=Your Name user.email=you@example.com
Creating and Getting Repositories
A repository is your project folder with superpowers. Git stores its entire history inside a hidden .git folder. There are two ways to get one: create a fresh one or download an existing one.
git initWhat it does
Analogy
Scenario
my-portfolio and run git init. From that moment Git is watching the folder.Warning
git init in a folder that already has files — Git will not delete anything.$ mkdir my-portfolio && cd my-portfolio
$ git init
$ git init my-portfolioInitialized empty Git repository in /my-portfolio/.git/
git cloneWhat it does
Analogy
Scenario
Warning
origin is saved so you can push and pull without typing the URL again.$ git clone https://github.com/user/repo.git
$ git clone https://github.com/user/repo.git my-folder
$ git clone --depth 1 https://github.com/user/repo.gitCloning into 'repo'... remote: Counting objects: 143, done.
The Everyday Workflow
Most of your time with Git follows one loop: status → add → commit → push.
Analogy
Think of it like shipping a package. You check what needs packing with status. You put things in the box with add. You seal and label it with commit. You ship it with push.
git statusWhat it does
Scenario
index.html and created a new style.css. Run git status to get a clear picture.$ git status
$ git status -sOn branch main Changes not staged for commit: modified: index.html Untracked files: style.css # Short format: M index.html ?? style.css
git addWhat it does
Analogy
Scenario
Warning
git add -p to review each chunk of changes before staging.$ git add index.html
$ git add .
$ git add -A
$ git add -pgit commitWhat it does
Analogy
Scenario
Warning
--amend on commits you have not pushed yet.$ git commit -m "Add navigation menu to homepage"
$ git commit
$ git commit -am "Fix typo in nav"
$ git commit --amend -m "Better message"[main a3f9d2c] Add navigation menu to homepage 2 files changed, 34 insertions(+)
Tip: Write messages in present tense. "Add login form" not "Added login form".
git pushWhat it does
Scenario
git push to upload them to GitHub.Warning
git push --force on a shared branch. Use --force-with-lease instead.$ git push
$ git push -u origin main
$ git push -u origin feature/login
$ git push --force-with-leaseTo github.com:user/repo.git f3a1200..a3f9d2c main -> main
Viewing History and Changes
One of Git's most powerful features is being able to see exactly what changed, when, and who changed it.
git logWhat it does
Scenario
git log to browse recent commits.$ git log --oneline
$ git log --oneline --graph --all
$ git log --author="Carolina" --since="1 week ago" --oneline
$ git log -p index.htmla3f9d2c Add navigation menu to homepage 8c110e0 Fix broken image paths f3a1200 Initial commit
git diffWhat it does
Scenario
git diff to see every line.$ git diff
$ git diff --staged
$ git diff main feature/login
$ git diff HEAD~3@@ -1,3 +1,3 @@ font-size: 16px;- color: black;+ color: #333333; font-weight: 400;
git blameWhat it does
Scenario
git blame to find out who wrote it and when.$ git blame index.htmla3f9d2c (Carolina 2024-11-04) <nav class="menu"> 8c110e0 (Sarah 2024-10-28) <a href="/">home</a>
Branches — Working in Parallel
A branch is an independent copy of your project. Work freely without affecting the main codebase — experiment, break things, try ideas with zero risk.
🔍 Think of it this way
Your project is a book. The main branch is the published draft. When you want to write a new chapter, you photocopy the whole book (create a branch), write in that copy, and when you're happy, paste your chapter into the original (merge). The original was never at risk.
git branchCreate and manage branches$ git branch # list local branches (* = current)
* main
feature/dark-mode
$ git branch feature/dark-mode # create (stay on current branch)
$ git branch -m old-name new-name # rename
$ git branch -d feature/done # delete (merged only)
$ git branch -D feature/abandoned # force delete
$ git branch -a # list local + remote branchesgit switchMove between branchesWhat it does
$ git switch feature/login # switch to existing branch
$ git switch -c feature/login # create + switch in one step
# Older syntax (same result):
$ git checkout feature/login
$ git checkout -b feature/loginWarning
Merging and Rebasing — Combining Work
When you finish working on a feature branch you merge it back into main.
git mergeWhat it does
Analogy
Scenario
feature/contact-form. You switch back to main and merge.Warning
--abort if something goes wrong during the merge.$ git switch main
$ git merge feature/contact-form
$ git merge --no-ff feature/contact-form
$ git merge --abortUpdating f3a1200..a3f9d2c Fast-forward contact.html | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
Conflict Resolution: A conflict happens when two branches changed the same line in different ways. Open the file, delete the conflict markers, keep the version you want, then run git add . and git commit.
git rebaseRewrite branch historyWhat it does
🔍 Think of it this way
You branched 3 days ago and main has moved on. Rebase says: "Pretend I created my branch today." Your commits get replanted on the tip of the current main.
$ git switch feature/login
$ git rebase main
Successfully rebased and updated refs/heads/feature/login.
$ git rebase -i HEAD~4 # interactive: squash, reorder, edit last 4 commits
$ git rebase --abort
$ git rebase --continue # after resolving a conflictWarning
Working with Remote Repositories
A remote is a version of your repository stored on a server like GitHub or GitLab.
Analogy
Your local repo is a notebook on your desk. The remote is a copy in a shared filing cabinet that everyone on the team can access.
git remoteWhat it does
origin.Scenario
git init and now want to connect it to GitHub.$ git remote -v
$ git remote add origin https://github.com/user/repo.git
$ git remote add upstream https://github.com/original/repo.git
$ git remote rename origin production
$ git remote set-url origin git@github.com:user/repo.gitorigin https://github.com/user/repo.git (fetch) origin https://github.com/user/repo.git (push)
git fetchWhat it does
Analogy
Tip: Always fetch before starting work on a team project.
$ git fetch origin
$ git log origin/main --onelineFrom github.com:team/project f3a1200..8c110e0 main -> origin/main
git pullWhat it does
git fetch and git merge in one step.Scenario
git pull to download and merge.Warning
$ git pull
$ git pull --rebase
$ git pull --ff-onlyUpdating f3a1200..8c110e0 Fast-forward index.html | 12 ++++++++++++ 1 file changed, 12 insertions(+)
Undoing Changes
Mistakes happen. Git gives you several tools to undo them.
Analogy
restore is Ctrl+Z.reset is crumpling up a piece of paper.revert is writing a correction note that cancels the old page but keeps the original.
git restoreWhat it does
Scenario
Warning
git restore permanently discards your changes with no undo.$ git restore index.html
$ git restore .
$ git restore --staged index.html
$ git restore --source HEAD~2 index.htmlgit resetWhat it does
Scenario
--soft.Warning
git reset --hard destroys your changes permanently.$ git reset --soft HEAD~1
$ git reset HEAD~1
$ git reset --hard HEAD~1git revertWhat it does
Scenario
$ git revert a3f9d2c
$ git revert HEAD
$ git revert HEAD~3..HEAD
$ git revert --no-commit a3f9d2c[main 9e8d7c6] Revert "Remove dark mode toggle" 1 file changed, 24 insertions(+)
Tip: If the commit was already pushed use revert. If it is only local you can use reset.
Stashing — Save Work Temporarily
Sometimes you are in the middle of work but need to quickly switch to something else without committing half-finished code.
Analogy
Stash is like a pause button. You tuck half-finished work into a hidden pocket, your directory goes clean, you handle the emergency, then resume exactly where you stopped.
git stashScenario
main, come back and pop your stash.Warning
-m. Without it stashes look identical.Save & inspect
$ git stash
$ git stash push -m "WIP: add login validation"
$ git stash -u
$ git stash listSaved working directory and index state WIP on main f3a1200
stash@{0}: On feature/login: WIP add login validation
stash@{1}: WIP on main: emergency hotfixRestore & clean
$ git stash pop
$ git stash apply stash@{1}
$ git stash drop stash@{0}
$ git stash clearTip: Always give your stash a description with -m.
Advanced Tools
These commands are less common in daily work, but become essential when you need to debug tricky problems or recover from mistakes.
git bisectWhat it does
Analogy
Scenario
$ git bisect start
$ git bisect bad
$ git bisect good v1.0.0
# Output:
# Bisecting: 39 revisions left to test after this
$ git bisect good
$ git bisect bad
# Output:
# a3f9d2c is the first bad commit
$ git bisect reset
$ git bisect run npm testTip: Automate the search with git bisect run npm test.
git reflogWhat it does
Scenario
git reset --hard HEAD~5 by mistake. Five commits of work — gone. Reflog keeps a record of every place HEAD has been in the last 90 days.$ git reflog
# Output:
# a3f9d2c HEAD@{0}: reset: moving to HEAD~5 (the mistake)
# 9e8d7c6 HEAD@{1}: commit: Add payment integration
# 5f4e3d2 HEAD@{5}: commit: Initial checkout flow
$ git reset --hard 5f4e3d2
# Output: recovered — all 5 commits restoredTip: Reflog is stored locally for 90 days only. Push your work regularly to a remote as a real backup.
Quick Reference Cheat Sheet
| Command | What it does | When to use it |
|---|---|---|
git config --global | Set name and email | Once when setting up Git |
git init | Create new repository | Starting a brand new project |
git clone <url> | Download remote repo | Joining an existing project |
git status | See what has changed | All the time — before every add |
git add . | Stage all changes | When you want to include everything |
git commit -m | Save a snapshot | After staging your changes |
git push | Upload to remote | After committing to share work |
git pull | Download and apply | Start of every work session |
git fetch | Download without applying | To see what teammates pushed |
git log --oneline | Compact history | Finding a specific commit |
git diff | See exact line changes | Before staging to review your work |
git blame <file> | See who wrote each line | Understanding old code |
git branch <name> | Create a branch | Starting a new feature or fix |
git switch <branch> | Move to a branch | Changing what you are working on |
git merge <branch> | Combine branches | Feature is ready for main |
git rebase <branch> | Replay commits on top | Clean history before sharing |
git stash | Hide work temporarily | Urgent context switch needed |
git stash pop | Restore hidden work | When you return to the task |
git restore <file> | Discard file changes | Throwing away bad edits |
git reset --soft HEAD~1 | Undo commit, keep staged | Committed too early |
git reset --hard HEAD~1 | Undo and delete changes | Nuclear option — be certain |
git revert <hash> | Safely undo a commit | Undoing something already pushed |
git bisect start | Binary search for a bug | Bug appeared somewhere in history |
git reflog | Recover lost commits | Emergency after bad resets |