Git Crash Course Hero
Version Control

Git Crash Course: Essential Commands Every QA Must Know

Carolina YepesCarolina Yepes March 5, 2026UpdatedMarch 5, 2026 25 min read 10 chapters

Crash 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.

25 min read10 chapters30+ commandsBeginner → Advanced
01

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.

Commandgit config

What it does

Reads and writes Git settings. The --global flag means the setting applies to every project on your computer.

Analogy

Like filling out a name tag before a conference. You do it once and it follows you everywhere.

Scenario

You just installed Git on your laptop. Before touching any project, you run these commands so every commit carries your identity.

Warning

Omit --global inside a specific project folder to set a different identity just for that project — useful on shared computers.
bash
$ git config --global user.name "Your Name"
$ git config --global user.email "you@example.com"
$ git config --global core.editor "code --wait"
$ git config --list
Output
user.name=Your Name
user.email=you@example.com
02

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.

Commandgit init

What it does

Turns the current folder into a Git repository. Nothing is tracked yet — it just sets the stage.

Analogy

Like buying a brand new notebook. The pages are blank but the system is ready for you to start writing.

Scenario

You decide to build your portfolio website. You create a folder called my-portfolio and run git init. From that moment Git is watching the folder.

Warning

You can run git init in a folder that already has files — Git will not delete anything.
bash
$ mkdir my-portfolio && cd my-portfolio
$ git init
$ git init my-portfolio
Output
Initialized empty Git repository in /my-portfolio/.git/
Commandgit clone

What it does

Copies a remote repository onto your computer including the full history and all files.

Analogy

Like photocopying a colleague's entire notebook including all their old notes.

Scenario

A colleague has a project on GitHub and invites you to collaborate. You clone the entire repo in one command.

Warning

After cloning, Git automatically remembers where you downloaded from. That origin is saved so you can push and pull without typing the URL again.
bash
$ 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.git
Output
Cloning into 'repo'...
remote: Counting objects: 143, done.
03

The Everyday Workflow

Most of your time with Git follows one loop: statusaddcommitpush.

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.

Commandgit status

What it does

Shows which files were modified, which are ready to be saved, and which are brand new files Git has never seen.

Scenario

You edited index.html and created a new style.css. Run git status to get a clear picture.
bash
$ git status
$ git status -s
Output
On branch main
Changes not staged for commit:
  modified:   index.html

Untracked files:
  style.css

# Short format:
 M index.html
?? style.css
Commandgit add

What it does

Moves changes to the staging area — a preparation zone. Nothing is permanently saved yet.

Analogy

The staging area is like a shopping cart before checkout. Add items, remove them, review them — nothing is final until you commit.

Scenario

You edited three files but only want to save two of them together in this commit.

Warning

Use git add -p to review each chunk of changes before staging.
bash
$ git add index.html
$ git add .
$ git add -A
$ git add -p
Commandgit commit

What it does

Takes everything in the staging area and saves it as a permanent snapshot in the history.

Analogy

A commit is like a bookmark. It records exactly where you are in the code.

Scenario

You have staged your files. Now you save them with a clear message. Six months later you or a teammate will read that message.

Warning

Only use --amend on commits you have not pushed yet.
bash
$ git commit -m "Add navigation menu to homepage"
$ git commit
$ git commit -am "Fix typo in nav"
$ git commit --amend -m "Better message"
Output
[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".

Commandgit push

What it does

Sends your local commits to the remote repository so others can see your work.

Scenario

You made three commits on your laptop. Run git push to upload them to GitHub.

Warning

Never use git push --force on a shared branch. Use --force-with-lease instead.
bash
$ git push
$ git push -u origin main
$ git push -u origin feature/login
$ git push --force-with-lease
Output
To github.com:user/repo.git
   f3a1200..a3f9d2c  main -> main
04

Viewing History and Changes

One of Git's most powerful features is being able to see exactly what changed, when, and who changed it.

Commandgit log

What it does

Shows all commits from newest to oldest with author, date, and message.

Scenario

A bug appeared this week. You open git log to browse recent commits.
bash
$ git log --oneline
$ git log --oneline --graph --all
$ git log --author="Carolina" --since="1 week ago" --oneline
$ git log -p index.html
Output
a3f9d2c Add navigation menu to homepage
8c110e0 Fix broken image paths
f3a1200 Initial commit
Commandgit diff

What it does

Shows exactly which lines were added (green +) or removed (red −).

Scenario

You edited your CSS but can't remember exactly what you changed. Run git diff to see every line.
bash
$ git diff
$ git diff --staged
$ git diff main feature/login
$ git diff HEAD~3
Output
@@ -1,3 +1,3 @@  font-size: 16px;-  color: black;+ color: #333333;  font-weight: 400;
Commandgit blame

What it does

Annotates every line of a file with the commit hash, author name, and date of the last change.

Scenario

You find a confusing line of code. Run git blame to find out who wrote it and when.
bash
$ git blame index.html
Output
a3f9d2c (Carolina  2024-11-04) <nav class="menu">
8c110e0 (Sarah     2024-10-28) <a href="/">home</a>
05

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.

Commandgit branchCreate and manage branches
bash
$ 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 branches
Commandgit switchMove between branches

What it does

Changes your working directory to reflect a different branch. All your files update instantly.
bash
$ 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/login

Warning

Always commit or stash your work before switching branches. Uncommitted changes can follow you — or Git may refuse to switch.
06

Merging and Rebasing — Combining Work

When you finish working on a feature branch you merge it back into main.

Commandgit merge

What it does

Takes commits from another branch and replays them onto your current branch.

Analogy

Like merging two parallel timelines into one.

Scenario

You spent three days building a contact form on feature/contact-form. You switch back to main and merge.

Warning

Use --abort if something goes wrong during the merge.
bash
$ git switch main
$ git merge feature/contact-form
$ git merge --no-ff feature/contact-form
$ git merge --abort
Output
Updating 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.

Commandgit rebaseRewrite branch history

What it does

Replays your branch's commits on top of another branch, as if you had branched off later. Creates a clean, linear history.

🔍 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.

bash
$ 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 conflict

Warning

Never rebase a branch other people are using. Rebasing rewrites history — anyone with the old version of your branch will have conflicts.
07

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.

Commandgit remote

What it does

Lists, adds, renames, or removes the remote connections. The default remote is always called origin.

Scenario

You created a local project with git init and now want to connect it to GitHub.
bash
$ 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.git
Output
origin  https://github.com/user/repo.git (fetch)
origin  https://github.com/user/repo.git (push)
Commandgit fetch

What it does

Downloads all new commits from the remote but does NOT change any of your local files.

Analogy

Fetching is like receiving a package at the door without opening it.

Tip: Always fetch before starting work on a team project.

bash
$ git fetch origin
$ git log origin/main --oneline
Output
From github.com:team/project
   f3a1200..8c110e0  main       -> origin/main
Commandgit pull

What it does

Combines git fetch and git merge in one step.

Scenario

You sit down to work. Your teammate pushed changes last night. Run git pull to download and merge.

Warning

Always commit or stash before pulling.
bash
$ git pull
$ git pull --rebase
$ git pull --ff-only
Output
Updating f3a1200..8c110e0
Fast-forward
 index.html | 12 ++++++++++++
 1 file changed, 12 insertions(+)
08

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.

Commandgit restore

What it does

Throws away changes in your working directory restoring files to their last committed state.

Scenario

You spent an hour trying a new approach. It looks terrible. Throw away all those changes.

Warning

git restore permanently discards your changes with no undo.
bash
$ git restore index.html
$ git restore .
$ git restore --staged index.html
$ git restore --source HEAD~2 index.html
Commandgit reset

What it does

Moves your current branch backward to an older commit.

Scenario

You just committed but immediately realized you forgot to include an important file. Undo with --soft.

Warning

git reset --hard destroys your changes permanently.
bash
$ git reset --soft HEAD~1
$ git reset HEAD~1
$ git reset --hard HEAD~1
Commandgit revert

What it does

Creates a brand new commit that does the opposite of a previous commit. The original bad commit stays in the history.

Scenario

You pushed a commit that accidentally deleted an important feature. Use revert to create a new undo commit that everyone can safely pull.
bash
$ git revert a3f9d2c
$ git revert HEAD
$ git revert HEAD~3..HEAD
$ git revert --no-commit a3f9d2c
Output
[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.

09

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.

Commandgit stash

Scenario

You are mid-feature when an urgent bug report lands. You stash it, fix the bug on main, come back and pop your stash.

Warning

Always give your stash a description with -m. Without it stashes look identical.

Save & inspect

bash
$ git stash
$ git stash push -m "WIP: add login validation"
$ git stash -u
$ git stash list
Output
Saved working directory and index state WIP on main f3a1200

stash@{0}: On feature/login: WIP add login validation
stash@{1}: WIP on main: emergency hotfix

Restore & clean

bash
$ git stash pop
$ git stash apply stash@{1}
$ git stash drop stash@{0}
$ git stash clear

Tip: Always give your stash a description with -m.

10

Advanced Tools

These commands are less common in daily work, but become essential when you need to debug tricky problems or recover from mistakes.

Commandgit bisect

What it does

Performs a binary search through your commit history to find exactly which commit introduced a bug.

Analogy

Imagine a book with 1,000 pages and somewhere there's a typo. Instead of reading every page, bisect opens to page 500 and asks: "Is the typo before or after this page?"

Scenario

Your app was working perfectly 2 weeks ago, but something broke since then. You have 80 commits in between.
bash
$ 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 test

Tip: Automate the search with git bisect run npm test.

Commandgit reflog

What it does

Shows a log of every position HEAD has ever been at, even when those commits are no longer on any branch. Your last resort for recovering lost work.

Scenario

You ran 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.
bash
$ 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 restored

Tip: Reflog is stored locally for 90 days only. Push your work regularly to a remote as a real backup.

Quick Reference Cheat Sheet

CommandWhat it doesWhen to use it
git config --globalSet name and emailOnce when setting up Git
git initCreate new repositoryStarting a brand new project
git clone <url>Download remote repoJoining an existing project
git statusSee what has changedAll the time — before every add
git add .Stage all changesWhen you want to include everything
git commit -mSave a snapshotAfter staging your changes
git pushUpload to remoteAfter committing to share work
git pullDownload and applyStart of every work session
git fetchDownload without applyingTo see what teammates pushed
git log --onelineCompact historyFinding a specific commit
git diffSee exact line changesBefore staging to review your work
git blame <file>See who wrote each lineUnderstanding old code
git branch <name>Create a branchStarting a new feature or fix
git switch <branch>Move to a branchChanging what you are working on
git merge <branch>Combine branchesFeature is ready for main
git rebase <branch>Replay commits on topClean history before sharing
git stashHide work temporarilyUrgent context switch needed
git stash popRestore hidden workWhen you return to the task
git restore <file>Discard file changesThrowing away bad edits
git reset --soft HEAD~1Undo commit, keep stagedCommitted too early
git reset --hard HEAD~1Undo and delete changesNuclear option — be certain
git revert <hash>Safely undo a commitUndoing something already pushed
git bisect startBinary search for a bugBug appeared somewhere in history
git reflogRecover lost commitsEmergency after bad resets

Tags

#Git#Version Control#DevOps#QA Engineering#Automation#CI/CD#Beginner Guide

CAROLINA YEPES

Senior QA Engineer / SDET

Delivering reliable software through automation excellence

© 2025 Carolina Yepes. All rights reserved.

Powered by Readdy
Talk with Us