What you'll learn
- Explain how changes move between working directory, staging, local and remote repositories
- Write small, readable commits and collaborate through branches and pull requests
- Choose the right undo: restore, stash, revert, reset or reflog
- Build a GitHub Actions workflow and enforce it with branch protection
- Keep secrets out of repositories and harden CI/CD pipelines
Each lesson is tagged Junior, Mid or Expert, so you can start where you are. Finish with the lab and the quiz; a score of 4 out of 5 marks the course complete in this browser.
The lessons below are in English for now, because they quote technical names, commands and log fields. An Arabic version is planned.
Course map
Each module moves from fundamentals to applied work to an expert challenge. Exercises have worked solutions: try first, then open the solution. 10 modules · 21 exercises · ~4 hours
- 0Start here: version control, Git and GitHubJuniorMidExpert20 min · 1 exercises
- 1Your first repository and commitsJuniorMidExpert25 min · 3 exercises
- 2Reading history and changesJuniorMidExpert20 min · 3 exercises
- 3Branches, merging and conflictsJuniorMidExpert30 min · 2 exercises
- 4Remotes and GitHub collaborationJuniorMidExpert25 min · 2 exercises
- 5Undo and recoverJuniorMidExpert30 min · 3 exercises
- 6.gitignore, tags and releasesJuniorMidExpert15 min · 2 exercises
- 7CI/CD with GitHub ActionsJuniorMidExpert35 min · 2 exercises
- 8DevSecOps: securing the repository and pipelineJuniorMidExpert25 min · 1 exercises
- 9Cheat sheet, assessment and expert challengeJuniorMidExpert15 min · 2 exercises
No prior experience is needed. Module 0 covers the architecture, installation and configuration, and sets up the project you extend in every module. Each command is labelled with its impact (read-only, changes files, changes the system, uses the network). Work on a computer or virtual machine you control.
Start here: version control, Git and GitHub
Goal: Understand what Git records and why, how Git differs from GitHub, install and configure Git, and prepare the project.
Version control and Git
Version control records every change to a set of files with its author, time and reason. Git is a distributed version control system: every copy (clone) holds the complete history, so work continues offline and any copy can restore the others.
A shared history answers audit questions such as 'who opened port 23, when, and with whose approval?', lets several engineers change the same files in parallel, and makes every change reviewable and reversible. Git is also the trigger for CI/CD pipelines and GitOps deployments, so it sits at the start of most delivery and change-management processes, for application code, infrastructure as code, firewall policies and detection rules alike.
Git stores commits: snapshots of the whole project. Each commit is identified by a SHA hash of its content and metadata (usually shown abbreviated to 7 characters) and points to its parent. Because each hash covers the parent's hash too, history cannot be altered silently: changing an old commit changes every hash after it.
Quick check: Why can't an old commit be changed without anyone noticing?
Changing one commit changes its hash and the hash of every later commit.
| Symptom | Likely cause | Fix |
|---|---|---|
| the repository grows very large | Git keeps every version of every file, including binaries | keep binaries out, or use Git LFS |
| diffs of documents are unreadable | binary formats such as .docx | store text formats (Markdown, YAML, CSV) where history matters |
Git and GitHub
Git is the version control program on your computer. GitHub is a hosting service built around Git: it stores a shared copy of the repository (the remote) and adds collaboration features. GitLab and Bitbucket are alternatives that work the same way.
Teams need one agreed copy of the code, a place to review changes before they are accepted, and automation that tests every change. Git provides the history; GitHub provides the shared copy, pull requests, Actions (CI/CD) and security features.
| Term | Meaning |
|---|---|
| Repository (repo) | a project folder whose history Git tracks |
| Commit | a saved snapshot with author, message and parent |
| Branch | a movable label for a line of work |
| Remote / origin | a copy of the repository on a server; origin is the usual name of the main one |
| Clone | a full local copy of a remote repository |
| Push / pull / fetch | send commits / receive and merge / receive only |
| Pull request (PR) | a request to merge a branch, with review and checks |
| Fork | your own server-side copy of someone else's repository |
Quick check: Which of these needs GitHub (or a similar service) rather than Git alone?
Commits and history are local Git features; pull requests are a hosting-service feature.
The four areas
Changes move through four places: the working directory (where you edit), the staging area (what you choose to include in the next snapshot), the local repository (saved history in the hidden .git folder) and the remote repository (the shared copy on GitHub).
Knowing where a change currently is explains almost every Git message and every undo command. The staging step lets you put exactly one logical change in each commit.
git add rules.txt: the change is staged.git commit -m "…": a snapshot is saved in the local history.git push: the team can now see it.Quick check: You edited a file and ran git commit, but the change is not in the commit. Why?
Only staged changes go into a commit.
Install and configure Git
Git is a command-line program. After installing it, you set your name and e-mail once; Git writes them into every commit you make.
Commits must show who made each change: code review, audit trails and incident investigations rely on it.
Install Git for Windows from git-scm.com (the defaults are fine) or winget install Git.Git. Use Git Bash or Windows Terminal; Git Bash runs every command in this course unchanged.
xcode-select --install # includes git
# or: brew install gitsudo apt update && sudo apt install -y git~/.gitconfig).--show-origin adds the file each value comes from.git --version
git config --global user.name "Rana Al-Harbi"
git config --global user.email rana@example.com
git config --global init.defaultBranch main
git config --global --listgit version 2.43.0 user.name=Rana Al-Harbi user.email=rana@example.com init.defaultbranch=main
Exercise 1Junior
Show where your e-mail setting is stored.
Worked solution
git config --list --show-origin | grep user.emailfile:/home/rana/.gitconfig user.email=rana@example.com
| Symptom | Likely cause | Fix |
|---|---|---|
| 'git' is not recognized | not installed, or the terminal was opened before installing | install, then open a new terminal |
| commits show the wrong name | a repository-level setting overrides the global one | git config --list --show-origin shows which file wins |
Tools in this course
The distributed version control system: history, branches, merges, all local.
Use it for: every project, every team
Integrates with: every editor, IDE and CI service
Hosting with pull requests, Actions, Packages and security features.
Use it for: open source and most companies
Integrates with: Actions, Dependabot, CodeQL, Slack, Jira
One application for repositories, CI/CD, registry and security scanning; also self-hosted.
Use it for: teams wanting an integrated or on-premises platform
Integrates with: Kubernetes, Terraform, Jira
Atlassian's Git hosting with Pipelines.
Use it for: teams on Jira and Confluence
Integrates with: Jira, Confluence, Pipelines
Editor with built-in Git: staging, diffs, conflict resolution.
Use it for: a visual view of the same commands
Integrates with: Git, GitHub Pull Requests extension
The firewall-rules repository
Goal: You are on the network team at Rimal Logistics. The edge firewall rules will live in Git, so every change is reviewed, tested by CI and traceable.
Each rule has the form allow|deny PORT/PROTOCOL from SOURCE. Create the project folder and the first two files (they are not under version control yet):
mkdir -p ~/firewall-rules && cd ~/firewall-rules
printf 'allow 22/tcp from 10.0.0.0/8\nallow 443/tcp from any\ndeny 23/tcp from any\n' > rules.txt
printf '# firewall-rules\nEdge firewall policy for Rimal Logistics.\n' > README.md
ls
cat rules.txtREADME.md rules.txt allow 22/tcp from 10.0.0.0/8 allow 443/tcp from any deny 23/tcp from any
printf writes text to a file and cat prints it; you can also create the files in any editor.
Your first repository and commits
Goal: Create a repository, read git status, stage and commit changes, and write commit messages your team can use.
Free account Create a free account or sign in to continue this course.
Reading history and changes
Goal: Read the history as a list or a graph, see exactly what changed, and find out who changed a line and why.
Free account Create a free account or sign in to continue this course.
Branches, merging and conflicts
Goal: Work on changes in isolation, bring them back, and resolve conflicts correctly.
Free account Create a free account or sign in to continue this course.
Remotes and GitHub collaboration
Goal: Connect to GitHub, push and pull safely, work with a colleague, and contribute through pull requests.
Free account Create a free account or sign in to continue this course.
Undo and recover
Goal: Choose the right undo command for each situation, and recover work that seems lost.
Free account Create a free account or sign in to continue this course.
.gitignore, tags and releases
Goal: Keep generated files and secrets out of the repository, and mark approved versions with tags.
Free account Create a free account or sign in to continue this course.
CI/CD with GitHub Actions
Goal: Automate testing of every change with a GitHub Actions workflow, require it before merging, and deploy with approvals.
Free account Create a free account or sign in to continue this course.
DevSecOps: securing the repository and pipeline
Goal: Stop secrets before they are committed, respond correctly when one leaks, and harden workflows against supply-chain attacks.
Free account Create a free account or sign in to continue this course.
Cheat sheet, assessment and expert challenge
Goal: Consolidate the commands on one page, then apply the whole workflow on your own.
Free account Create a free account or sign in to continue this course.
Quick reference (the cheat-sheet lessons and the PDF content)
How Git moves your changes
Four places, a few verbs. Most confusion disappears once you know which area a command touches.
First-time setup
git config --global user.name "Rana Al-Harbi"
git config --global user.email "rana@example.com"
git config --global init.defaultBranch main
git config --global pull.rebase true # linear history
git config --global fetch.prune true
git config --global core.autocrlf input # Windows: true
# sign commits with your SSH key
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign trueThe daily loop
git switch -c feat/rate-limit # new branch
git status -sb # what changed?
git diff # unstaged changes
git add -p # stage hunk by hunk
git commit -m "auth: rate-limit failed logins"
git fetch && git rebase origin/main
git push -u origin feat/rate-limit
# open a pull request, address review
git push --force-with-lease # after a rebase onlyCommits people can read
| Good | Bad |
|---|---|
auth: rate-limit failed logins per IP | fix |
| One logical change per commit | Formatting, refactor and feature mixed |
| Body explains why, links the ticket | "see Slack" |
| Small and reviewable (under ~400 lines) | 2,000-line "WIP" |
Conventional prefix: feat: fix: docs: chore: | Random wording that breaks release notes |
Why it matters
- Faster review and fewer bugs
git bisectfinds the bad commit- Release notes write themselves
- Audit: who changed what and why
Branching model
Merge, squash or rebase?
| Option | History looks like | Use when | Watch out |
|---|---|---|---|
| Merge commit | Branches and merge points kept | Long-lived release branches; you want the full story | Noisy graph |
| Squash merge | One commit per pull request on main | Most feature PRs; clean main | Loses intermediate commits |
| Rebase | Linear, as if written on latest main | Updating your own branch before review | Never rebase commits others have pulled |
| Cherry-pick | Copy one commit to another branch | Backporting a fix to a release | Duplicate commits if overused |
Undo almost anything
| Situation | Command | Safe on shared branch? |
|---|---|---|
| Discard local edits to a file | git restore path | Yes (local only) |
| Unstage a file | git restore --staged path | Yes |
| Fix the last commit message or add a file | git commit --amend | Only before push |
| Undo a pushed commit | git revert <sha> | Yes: adds an inverse commit |
| Move branch back, keep changes | git reset --soft HEAD~1 | Only before push |
| Throw away commits and changes | git reset --hard <sha> | No: rewrites history |
| Find a 'lost' commit | git reflog then git switch -c rescue <sha> | Yes |
| Find which commit broke it | git bisect start; git bisect bad; git bisect good v2.3 | Yes |
| Park work in progress | git stash push -m wip; git stash pop | Yes |
Merge conflicts, step by step
Conflict markers <<<<<<<, =======, >>>>>>> must all be gone before you commit. Stuck? git rebase --abort returns to where you started.
Repository security
Protect the main branch
- Require pull requests and at least one review
- Require status checks (CI, tests, scans) to pass
- Block force-push and deletion
- Require signed commits for release branches
- CODEOWNERS for sensitive paths (
/infra,/.github) - MFA for every member
Keep secrets out
.gitignore:.env, keys,*.tfstate- Pre-commit secret scanning: gitleaks or trufflehog
- Platform push protection (GitHub, GitLab)
- Leaked a secret? Rotate it first. Rewriting history (
git filter-repo) does not undo forks, clones or caches
git log --oneline --graph --decorate -20 before every push. If the graph surprises you, stop and look.Key terms
- Commit
- A snapshot of staged changes with an author, message and parent.
- Branch / HEAD
- A movable label on a commit / the pointer to the branch you are on.
- Pull request
- A proposal to merge a branch, with review and CI checks.
- Revert vs reset
- revert adds a commit that undoes another; reset moves the branch back (only for unpushed work).
- Workflow
- A YAML file in .github/workflows that runs jobs on events such as pull_request.
- Required status check
- A CI job that must pass before branch protection allows a merge.
Hands-on lab
Free account Create a free account or sign in to continue this course.
Knowledge check
Answer all five questions, then check your answers. Each answer comes with a short explanation.
Further reading
- Pro Git book git-scm.com
- Git reference git-scm.com
- GitHub Actions documentation docs.github.com
- Security hardening for GitHub Actions docs.github.com
- GitHub: about protected branches docs.github.com