Sign in Start free

EngineeringFree course

Git, GitHub and CI/CD

Version control the way teams work, from the first commit to an automated pipeline: the four areas, clean commits, branches and conflicts, GitHub pull requests, undoing mistakes safely, GitHub Actions CI/CD, and DevSecOps controls for the repository and pipeline.

  • Level Junior → Mid
  • Time 240 min
  • Modules 10
  • Exercises 21 with worked solutions
  • Includes Lab, 5-question quiz, references

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

  1. 0Start here: version control, Git and GitHubJuniorMidExpert20 min · 1 exercises
  2. 1Your first repository and commitsJuniorMidExpert25 min · 3 exercises
  3. 2Reading history and changesJuniorMidExpert20 min · 3 exercises
  4. 3Branches, merging and conflictsJuniorMidExpert30 min · 2 exercises
  5. 4Remotes and GitHub collaborationJuniorMidExpert25 min · 2 exercises
  6. 5Undo and recoverJuniorMidExpert30 min · 3 exercises
  7. 6.gitignore, tags and releasesJuniorMidExpert15 min · 2 exercises
  8. 7CI/CD with GitHub ActionsJuniorMidExpert35 min · 2 exercises
  9. 8DevSecOps: securing the repository and pipelineJuniorMidExpert25 min · 1 exercises
  10. 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.

0

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.

20 min

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.

a1b2c3dAdd initial firewall rulese4f5a6bBlock RDPc7d8e9fAllow HTTPmainHEADEach arrow points to the parent commit.A branch is a label on a commit; HEAD marks the branch you are on.
GitGitHub · CI/CDGit foundationsfour areas, commitsstatus, add, commit, log, diffBranchesswitch, merge, conflictsHEAD, fast-forwardGitHub collaborationclone, push, pull, fetchpull requests, reviewsUndo and recoverrestore, stash, revertreset, reflogCI/CD with Actionsworkflows, jobs, stepschecks, environmentsDevSecOpshooks, secret scanningleast privilege, CODEOWNERS

Quick check: Why can't an old commit be changed without anyone noticing?

SymptomLikely causeFix
the repository grows very largeGit keeps every version of every file, including binarieskeep binaries out, or use Git LFS
diffs of documents are unreadablebinary formats such as .docxstore 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.

GitGita program on your computer• commits, branches, merges, history• works offline, fully local• free, open source (git-scm.com)• the same commands on every platformGitHubGitLabBitbucketGitHub, GitLab, Bitbucketservices that host Git repositories• remote repositories, access control• pull requests and code review• Actions: CI/CD pipelines• security: secret scanning, Dependabotpushfetch
Tools in this diagram:GitGitHubGitLabBitbucketVS Code
TermMeaning
Repository (repo)a project folder whose history Git tracks
Commita saved snapshot with author, message and parent
Brancha movable label for a line of work
Remote / origina copy of the repository on a server; origin is the usual name of the main one
Clonea full local copy of a remote repository
Push / pull / fetchsend commits / receive and merge / receive only
Pull request (PR)a request to merge a branch, with review and checks
Forkyour own server-side copy of someone else's repository

Quick check: Which of these needs GitHub (or a similar service) rather than Git alone?

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.

Working directoryfiles you editStaging areathe next snapshotLocal repository.git: saved historyRemote repositoryGitHub: shared copygit addgit commitgit pushgit fetchgit pull = fetch + merge into your current branchgit restore / reset
Step 1 of 4 You edit rules.txt: the change exists only in the working directory.
Working directoryfiles you editStaging areathe next snapshotLocal repository.git: saved historyRemote repositoryGitHub: shared copygit addgit commitgit pushgit fetchgit pull = fetch + merge into your current branchgit restore / reset
Step 2 of 4 git add rules.txt: the change is staged.
Working directoryfiles you editStaging areathe next snapshotLocal repository.git: saved historyRemote repositoryGitHub: shared copygit addgit commitgit pushgit fetchgit pull = fetch + merge into your current branchgit restore / reset
Step 3 of 4 git commit -m "…": a snapshot is saved in the local history.
Working directoryfiles you editStaging areathe next snapshotLocal repository.git: saved historyRemote repositoryGitHub: shared copygit addgit commitgit pushgit fetchgit pull = fetch + merge into your current branchgit restore / reset
Step 4 of 4 git push: the team can now see it.
Working directoryfiles you editStaging areathe next snapshotLocal repository.git: saved historyRemote repositoryGitHub: shared copygit addgit commitgit pushgit fetchgit pull = fetch + merge into your current branchgit restore / reset

Quick check: You edited a file and ran git commit, but the change is not in the commit. Why?

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.

2
--global applies to every repository of your user (stored in ~/.gitconfig).
5
Show what is set. --show-origin adds the file each value comes from.
shell
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 --list
1
Check the installation. Any version from 2.30 works with this course.
3
Identity written into every commit. Use the e-mail of your GitHub account.
4
Name of the first branch in new repositories.
Output
git 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
shell
git config --list --show-origin | grep user.email
Output
file:/home/rana/.gitconfig	user.email=rana@example.com
SymptomLikely causeFix
'git' is not recognizednot installed, or the terminal was opened before installinginstall, then open a new terminal
commits show the wrong namea repository-level setting overrides the global onegit config --list --show-origin shows which file wins

Tools in this course

GitCode

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

GitHubCode

Hosting with pull requests, Actions, Packages and security features.

Use it for: open source and most companies

Integrates with: Actions, Dependabot, CodeQL, Slack, Jira

GitLabCode

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

BitbucketCode

Atlassian's Git hosting with Pipelines.

Use it for: teams on Jira and Confluence

Integrates with: Jira, Confluence, Pipelines

Visual Studio CodeCode

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

Project step 0

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):

shell · project step 0
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.txt
Output
README.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.

Steps 1-2repo, commits, historyStep 3branches, conflictStep 4GitHub, PRSteps 5-6recover, ignore, tagStep 7CI workflowStep 8secure repo + pipeline
1

Your first repository and commits

Goal: Create a repository, read git status, stage and commit changes, and write commit messages your team can use.

25 min

Free account Create a free account or sign in to continue this course.

2

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.

20 min

Free account Create a free account or sign in to continue this course.

3

Branches, merging and conflicts

Goal: Work on changes in isolation, bring them back, and resolve conflicts correctly.

30 min

Free account Create a free account or sign in to continue this course.

4

Remotes and GitHub collaboration

Goal: Connect to GitHub, push and pull safely, work with a colleague, and contribute through pull requests.

25 min

Free account Create a free account or sign in to continue this course.

5

Undo and recover

Goal: Choose the right undo command for each situation, and recover work that seems lost.

30 min

Free account Create a free account or sign in to continue this course.

6

.gitignore, tags and releases

Goal: Keep generated files and secrets out of the repository, and mark approved versions with tags.

15 min

Free account Create a free account or sign in to continue this course.

7

CI/CD with GitHub Actions

Goal: Automate testing of every change with a GitHub Actions workflow, require it before merging, and deploy with approvals.

35 min

Free account Create a free account or sign in to continue this course.

8

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.

25 min

Free account Create a free account or sign in to continue this course.

9

Cheat sheet, assessment and expert challenge

Goal: Consolidate the commands on one page, then apply the whole workflow on your own.

15 min

Free account Create a free account or sign in to continue this course.

Quick reference (the cheat-sheet lessons and the PDF content)
1

How Git moves your changes

Junior

Four places, a few verbs. Most confusion disappears once you know which area a command touches.

Working treefiles you editStaging areathe next commitLocal repository.git historyRemoteorigin on GitHub/GitLabgit addgit commitgit pushgit restore --stagedgit fetchgit restore / git switchgit pull = git fetch + merge (or rebase)
2

First-time setup

Junior
shell
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 true
3

The daily loop

Junior
shell
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 only
4

Commits people can read

JuniorMid
GoodBad
auth: rate-limit failed logins per IPfix
One logical change per commitFormatting, 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 bisect finds the bad commit
  • Release notes write themselves
  • Audit: who changed what and why
5

Branching model

Mid
Trunk-based flow: short-lived branches, small pull requests, main always releasablemainfeat/login-rate-limitfix/cve-2026-xxxxfeat/audit-logtag v2.4.0PR: review + CI green + branch protection → squash or merge
6

Merge, squash or rebase?

Mid
OptionHistory looks likeUse whenWatch out
Merge commitBranches and merge points keptLong-lived release branches; you want the full storyNoisy graph
Squash mergeOne commit per pull request on mainMost feature PRs; clean mainLoses intermediate commits
RebaseLinear, as if written on latest mainUpdating your own branch before reviewNever rebase commits others have pulled
Cherry-pickCopy one commit to another branchBackporting a fix to a releaseDuplicate commits if overused
7

Undo almost anything

JuniorMidExpert
SituationCommandSafe on shared branch?
Discard local edits to a filegit restore pathYes (local only)
Unstage a filegit restore --staged pathYes
Fix the last commit message or add a filegit commit --amendOnly before push
Undo a pushed commitgit revert <sha>Yes: adds an inverse commit
Move branch back, keep changesgit reset --soft HEAD~1Only before push
Throw away commits and changesgit reset --hard <sha>No: rewrites history
Find a 'lost' commitgit reflog then git switch -c rescue <sha>Yes
Find which commit broke itgit bisect start; git bisect bad; git bisect good v2.3Yes
Park work in progressgit stash push -m wip; git stash popYes
8

Merge conflicts, step by step

JuniorMid

Conflict markers <<<<<<<, =======, >>>>>>> must all be gone before you commit. Stuck? git rebase --abort returns to where you started.

Pull or rebaseconflict reportedgit statuslists filesEditkeep the right linesTestbuild + testsgit addmark resolvedContinuerebase --continue
9

Repository security

MidExpert

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
Habit Run 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.

1Which command undoes a commit that is already pushed to a shared branch?
2What does git fetch change?
3A secret was committed and pushed. First step?
4Why add permissions: contents: read to a workflow?
5What makes a failing CI check actually block a merge?

Further reading

Put it into practice