SkillNavora
Git & GitHub Complete Guide
How Git works, daily commands, branches, collaboration, undo, Actions, Pages and AI agents

Git & GitHub Complete Guide

Git and GitHub from zero to confident: the mental model, setup with SSH and the GitHub CLI, the daily loop, branches and conflicts, pull requests and reviews, undoing mistakes, Actions, Pages and releases, and working with AI coding agents. Every terminal block is real output from Git 2.43, captured when this guide was built.

Checked against official sources in November 2026. Menu names and limits can change. Where a feature is plan-dependent, the lesson says so.

Contents

  1. 1. How Git works: snapshots, commits, branches and the three areas (18 min)
  2. 2. Set up Git and GitHub: install, identity, SSH keys, GitHub CLI and your first repository (20 min)
  3. 3. The daily Git loop: status, diff, add, commit, log, .gitignore and restore (20 min)
  4. 4. Branches, merging, conflicts, rebase and stash (25 min)
  5. 5. GitHub collaboration: remotes, push and pull, forks, pull requests, reviews and issues (25 min)
  6. 6. Undo anything safely: amend, reset, revert, reflog and leaked secrets (20 min)
  7. 7. GitHub Actions, Pages, releases and security features (22 min)
  8. 8. GitHub with AI: Copilot, the coding agent, Claude Code and Codex (20 min)

Sources: Pro Git book (https://git-scm.com/book/en/v2), GitHub Docs (https://docs.github.com), GitHub changelog (https://github.blog/changelog/)

Git & GitHub Complete Guide › Lesson 1 of 8 · about 18 minutes
Lesson 1

How Git works: snapshots, commits, branches and the three areas

The mental model that makes every Git command make sense: snapshots instead of differences, the working folder, staging area and repository, what a commit really contains, and why a branch is only a pointer.

Checked against official sources in November 2026. Lessons build on each other.
In plain words. Git is a camera for your project folder. Each commit is a photo of every file at that moment, with a caption and a link to the previous photo. A branch is a sticky note that says "we are here" on one photo, and it moves forward each time you take a new one.

Key ideas

Repository (repo)A project folder plus its full history, stored in a hidden .git folder.
CommitA saved snapshot of the whole project, with an author, date, message and a link to its parent commit.
Working treeThe files you see and edit.
Staging area (index)The list of changes you have chosen for the next commit.
BranchA movable name that points to one commit. HEAD tells Git which branch you are on.
Git vs GitHubGit is the free tool on your computer. GitHub is a website that hosts Git repositories and adds pull requests, issues, Actions and more.

How it works

1. Snapshots, not differences

Most people imagine Git stores a list of changes. It actually stores snapshots: each commit points to a full picture of the project. Files that did not change are not copied again; Git simply points to the same stored content. That is why switching branches is fast and why history is reliable.

Every piece of stored content gets an ID (a hash) calculated from the content itself, like 5e9b349. If even one character changes, the ID changes, so history cannot be quietly edited.

2. The three areas

AreaWhat it isCommands that move things
Working treeYour files on diskedit files; git restore to undo edits
Staging areaChanges chosen for the next commitgit add to stage; git restore --staged to unstage
RepositorySaved commits in .gitgit commit to save; git log to view

Staging lets you commit only part of your work: fix two bugs, then save them as two clean commits.

3. Look inside a real commit

These commands show what Git actually stored for the first commit of a small notes project. A commit points to a tree (the folder), the tree points to blobs (file contents), and the branch file simply holds the latest commit's ID.

Real terminal output (captured when this guide was built)
$ git cat-file -t HEAD
commit
$ git cat-file -p HEAD
tree ab39980f441eabb3f33aa3ba8c6846a18da78113
author Asha Learner <[email protected]> 1793594280 +0530
committer Asha Learner <[email protected]> 1793594280 +0530

Add README with the course title
$ git cat-file -p HEAD^{tree}
100644 blob c4302146ff40c2cbd6dabd9dec8498f32cdb086a	README.md
$ git cat-file -p HEAD:README.md
# My study notes
$ cat .git/HEAD
ref: refs/heads/main
$ cat .git/refs/heads/main
5e9b349eb22b7a59f77c79d033ec8e6a0a593b65

4. Branches are just pointers

  • main is a file in .git that contains one commit ID. A new commit on main moves that pointer forward.
  • Creating a branch creates a new pointer to the same commit. It costs almost nothing, so make branches freely.
  • HEAD is Git's "you are here". Normally it points to a branch (ref: refs/heads/main).
  • Merging joins two lines of history; when one branch is simply ahead, Git just moves the pointer (a fast-forward).

5. Where GitHub fits

Your computer has the complete repository. GitHub keeps another copy (a remote, usually called origin) so you can back up, share and collaborate. You push commits up, and fetch or pull other people's commits down. Pull requests, reviews, issues and Actions are GitHub features built around that shared copy.

Common mistakes and fixes

MistakeFix
Thinking GitHub and Git are the sameGit runs on your computer and works offline; GitHub hosts copies and adds collaboration tools.
Being afraid of branchesThey are just pointers; create one for every change.
Committing everything at the end of the weekCommit small, logical steps with clear messages.

Practice

  1. Draw the three areas on paper and write which command moves a change between each.
  2. In a test repository run git cat-file -p HEAD and find the tree, author and message.
  3. Explain to a friend why a branch costs almost nothing to create.

Quick check

Does Git store differences or snapshots?

Snapshots: each commit points to a full picture of the project; unchanged files are reused, not copied.

What does the staging area hold?

The changes you have chosen to include in the next commit.

What is inside .git/refs/heads/main?

The ID (hash) of the latest commit on main.

What is HEAD?

Git's pointer to where you are, normally the current branch.

Go further (official sources)

Git & GitHub Complete Guide › Lesson 2 of 8 · about 20 minutes
Lesson 2

Set up Git and GitHub: install, identity, SSH keys, GitHub CLI and your first repository

Install Git on Windows, macOS or Linux, set your name and email, create a GitHub account with two-factor authentication, connect with SSH or the GitHub CLI, and create and clone your first repository.

Checked against official sources in November 2026. Lessons build on each other.
In plain words. Setting up Git is like getting a new bank account: install the app, tell it who you are, prove your identity to the bank (GitHub) with a secure key, then open your first account (repository).

Key ideas

git configSaves settings such as your name and email, for one repository or globally.
SSH keyA key pair on your computer that proves to GitHub it is you, without typing a password.
Personal access tokenA password-like token for HTTPS; use fine-grained tokens with an expiry date.
GitHub CLI (gh)GitHub's official command-line tool: sign in, create repositories and pull requests from the terminal.
Two-factor authentication (2FA)A second check (app, passkey or security key) when you sign in. Required for code contributors on GitHub.

How it works

1. Install Git

SystemHow
WindowsDownload Git for Windows from git-scm.com and keep the defaults (it includes Git Bash and Git Credential Manager). Or run winget install --id Git.Git -e.
macOSRun git --version; macOS offers to install the Command Line Tools. Or brew install git.
Linuxsudo apt install git (Ubuntu/Debian) or sudo dnf install git (Fedora).

Check it worked:

Real terminal output (captured when this guide was built)
$ git --version
git version 2.43.0

2. Tell Git who you are

One-time setup
git config --global user.name "Your Name"
git config --global user.email "[email protected]"     # use the email on your GitHub account
git config --global init.defaultBranch main
git config --global pull.rebase false                 # or true, if your team prefers rebasing
git config --list --show-origin                       # see every setting and where it came from
Tip. To keep your email private, use the no-reply address from GitHub Settings, Emails (it looks like [email protected]).

3. Create your GitHub account safely

  1. Sign up at github.com with a professional username (it appears in your portfolio links).
  2. Turn on two-factor authentication: Settings › Password and authentication. Use an authenticator app or a passkey, and save the recovery codes.
  3. Add a profile photo, bio and a profile README (a repository named exactly like your username).

4. Connect with SSH (recommended)

Create and add an SSH key
ssh-keygen -t ed25519 -C "[email protected]"   # press Enter for the default file, add a passphrase
cat ~/.ssh/id_ed25519.pub                    # copy this PUBLIC key
# GitHub: Settings > SSH and GPG keys > New SSH key > paste > Add
ssh -T [email protected]                        # "Hi <username>! You've successfully authenticated"

Never share the private key (the file without .pub). Use one key per computer, and delete keys for computers you no longer use.

5. Or use the GitHub CLI

Sign in and create a repository from the terminal
# install: winget install --id GitHub.cli   |   brew install gh   |   see cli.github.com for Linux
gh auth login                 # choose GitHub.com, HTTPS or SSH, and log in with your browser
gh repo create study-notes --public --clone --add-readme
cd study-notes && git log --oneline

6. Your first repository from scratch

Here is a real first session: create a folder, start Git, and see what status reports.

Real terminal output (captured when this guide was built)
$ git init
Initialized empty Git repository in /home/asha/notes/.git/
$ git config user.name "Asha Learner"
$ git config user.email "[email protected]"
$ echo '# My study notes' > README.md
$ git status
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	README.md

nothing added to commit but untracked files present (use "git add" to track)
Stage and commit (real output)
$ git add README.md
$ git status --short
A  README.md
$ git commit -m "Add README with the course title"
[main (root-commit) 5e9b349] Add README with the course title
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
$ git log --oneline
5e9b349 Add README with the course title

To put it on GitHub, create an empty repository on github.com (no README), then follow Lesson 5 to add the remote and push.

Common mistakes and fixes

MistakeFix
Commits show the wrong name or emailSet user.name and user.email globally, and fix a single repository with git config (without --global).
Typing your GitHub password in the terminalGitHub does not accept account passwords for Git; use SSH, the GitHub CLI, or a token via the credential manager.
Sharing the private SSH keyOnly the .pub file is shared. If a private key leaks, delete it on GitHub and create a new one.

Practice

  1. Install Git, set your name and email, and run git config --list --show-origin.
  2. Create an SSH key, add it to GitHub and run ssh -T [email protected].
  3. Create a public repository called study-notes with gh or the website and clone it.

Quick check

Which command sets your name for every repository?

git config --global user.name "Your Name"

Which part of an SSH key do you paste into GitHub?

The public key (the .pub file).

Why turn on 2FA?

It protects your account and code; GitHub requires it for code contributors.

Go further (official sources)

Git & GitHub Complete Guide › Lesson 3 of 8 · about 20 minutes
Lesson 3

The daily Git loop: status, diff, add, commit, log, .gitignore and restore

The commands you will type every day, with real output: check what changed, stage, commit with a good message, read history, ignore files that should never be committed, and undo edits.

Checked against official sources in November 2026. Lessons build on each other.
In plain words. Your daily loop is: look (status, diff), choose (add), save (commit), and look back (log). Run git status whenever you are unsure; it always tells you where you are and what to do next.

Key ideas

git statusShows the branch, staged changes, unstaged changes and untracked files.
git diffShows line-by-line changes not yet staged (add --staged for staged ones).
git addStages a file's current content for the next commit.
git commit -mSaves staged changes as a commit with a message.
git logShows history; --oneline, --graph and --stat make it readable.
.gitignoreA list of files and folders Git should not track, such as secrets and build output.

How it works

1. A real day of work

Edit a file, create another, check, stage, commit and read history:

Real terminal output (captured when this guide was built)
$ printf '# My study notes\n\n## Git\n- commit = snapshot\n' > README.md
$ echo 'print("hello")' > hello.py
$ git status --short
 M README.md
?? hello.py
$ git diff
diff --git a/README.md b/README.md
index c430214..c76ade9 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,4 @@
 # My study notes
+
+## Git
+- commit = snapshot
$ git add README.md hello.py
$ git diff --staged --stat
 README.md | 3 +++
 hello.py  | 1 +
 2 files changed, 4 insertions(+)
$ git commit -m "Add Git notes and a hello script"
[main e26a370] Add Git notes and a hello script
 2 files changed, 4 insertions(+)
 create mode 100644 hello.py
$ git log --oneline --stat -1
e26a370 Add Git notes and a hello script
 README.md | 3 +++
 hello.py  | 1 +
 2 files changed, 4 insertions(+)

2. Write commit messages people can use

  • Start with a verb in the present tense: Add, Fix, Update, Remove.
  • Say what and why in under about 60 characters: Fix login error when email has capitals.
  • One logical change per commit. If you need "and", consider two commits.
  • For longer explanations, run git commit without -m and write a blank line then a body.

3. Ignore what should never be committed

Secrets (.env files, keys), dependency folders (node_modules, .venv), build output and editor files belong in .gitignore.

Real terminal output (captured when this guide was built)
$ mkdir -p __pycache__ && echo x > __pycache__/hello.cpython-312.pyc && echo 'API_KEY=secret' > .env
$ git status --short
?? .env
?? __pycache__/
$ printf '__pycache__/\n.env\n' > .gitignore
$ git status --short
?? .gitignore
$ git add .gitignore && git commit -q -m "Ignore cache files and .env"
$ git check-ignore -v .env
.gitignore:2:.env	.env
A starter .gitignore
# .gitignore for a Python or data project
.env
*.key
__pycache__/
.venv/
.ipynb_checkpoints/
data/raw/          # large or private data
*.log
.DS_Store
Careful. If a secret was ever committed, adding it to .gitignore does not remove it from history. Revoke and rotate the secret immediately, then clean history (see Lesson 6).

4. Undo edits safely

Real terminal output (captured when this guide was built)
$ echo 'oops, wrong line' >> README.md
$ git status --short
 M README.md
$ git restore README.md
$ git status --short
$ echo 'draft' > draft.txt && git add draft.txt
$ git restore --staged draft.txt
$ git status --short
?? draft.txt
$ rm draft.txt
You want toCommand
Throw away unstaged edits in a filegit restore file
Unstage a file but keep the editsgit restore --staged file
See what you are about to commitgit diff --staged
Stage only parts of a filegit add -p file (answer y or n per change)

5. Read history like a pro

Real terminal output (captured when this guide was built)
$ git log --oneline --graph -8
* 1ee8249 Revert "Add a wrong fact"
* d586c73 Add a wrong fact
* 7800ea1 Add tag definition
* addeeb7 Add quiz question 3
* 209b3bc Add glossary
* 6478e23 Add quiz question 2
*   14bb0e2 Merge feature/title: keep both ideas in the title
|\  
| * 1670ef3 Rename notes title
$ git log --oneline --author=Ravi
addeeb7 Add quiz question 3
$ git log --oneline -S "remote"
addeeb7 Add quiz question 3
$ git blame -s quiz.md
1e3e254e 1) Q1: What is a commit?
6478e235 2) Q2: What does git add do?
addeeb77 3) Q3: What is a remote?
$ git show --stat --format='%h %an %s' HEAD~1
d586c73 Asha Learner Add a wrong fact

 glossary.md | 1 +
 1 file changed, 1 insertion(+)
  • --author filters by person, -S "text" finds commits that added or removed that text.
  • git blame shows which commit last changed each line.
  • git show shows one commit's message and changes.

Common mistakes and fixes

MistakeFix
git add . without lookingRun git status and git diff first; check nothing secret or huge is included.
Messages like "update" or "final final"Describe what changed and why.
Committing a .env fileAdd it to .gitignore before the first commit; if it leaked, rotate the secret.

Practice

  1. Make three small changes and commit them as three separate commits with clear messages.
  2. Create a .gitignore, add a fake .env and confirm git status ignores it.
  3. Use git log -S to find the commit that added a word you choose.

Quick check

What does git diff --staged show?

The changes that are staged and will go into the next commit.

Which command throws away unstaged edits to a file?

git restore

Does adding a file to .gitignore remove it from earlier commits?

No. It only stops tracking new changes; committed secrets must be rotated and history cleaned.

Go further (official sources)

Git & GitHub Complete Guide › Lesson 4 of 8 · about 25 minutes
Lesson 4

Branches, merging, conflicts, rebase and stash

Work on features without breaking main: create and switch branches, fast-forward and three-way merges, read and resolve a real merge conflict, rebase a branch on main, and park unfinished work with stash.

Checked against official sources in November 2026. Lessons build on each other.
In plain words. A branch is a parallel draft. You write in your draft while main stays clean. Merging copies your finished draft back. A conflict is Git saying "you and someone else changed the same sentence; you choose the final wording".

Key ideas

git switch -cCreates a new branch and moves to it.
Fast-forward mergeWhen main has no new commits, Git just moves main's pointer to your branch.
Three-way mergeWhen both branches have new commits, Git creates a merge commit joining them.
Merge conflictBoth branches changed the same lines; Git marks them and asks you to decide.
RebaseReplays your branch's commits on top of the latest main, for a straight history.
StashTemporarily shelves uncommitted changes so you can switch tasks.

How it works

1. Branch and fast-forward merge

Real terminal output (captured when this guide was built)
$ git switch -c feature/quiz
Switched to a new branch 'feature/quiz'
$ echo 'Q1: What is a commit?' > quiz.md && git add quiz.md && git commit -q -m "Add quiz question 1"
$ git log --oneline --all
1e3e254 Add quiz question 1
fb1523a Ignore cache files and .env
e26a370 Add Git notes and a hello script
5e9b349 Add README with the course title
$ git switch main
Switched to branch 'main'
$ git merge feature/quiz
Updating fb1523a..1e3e254
Fast-forward
 quiz.md | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 quiz.md
$ git branch -d feature/quiz
Deleted branch feature/quiz (was 1e3e254).

Because main had no new commits, Git simply moved main forward ("Fast-forward"). No merge commit was needed.

2. A real merge conflict, resolved

Here both branches changed the first line of README.md. Read the markers, write the final version, then add and commit:

Real terminal output (captured when this guide was built)
$ git log --oneline --graph --all -4
* 2117d1a Change title on main
| * 1670ef3 Rename notes title
|/  
* 1e3e254 Add quiz question 1
* fb1523a Ignore cache files and .env
$ git merge feature/title
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
$ git status --short
UU README.md
$ cat README.md
<<<<<<< HEAD
# My Git and GitHub notes
=======
# Asha study notes
>>>>>>> feature/title

## Git
- commit = snapshot
$ printf '# Asha: Git and GitHub notes\n\n## Git\n- commit = snapshot\n' > README.md
$ git add README.md
$ git commit -q -m "Merge feature/title: keep both ideas in the title"
$ git log --oneline --graph -5
*   14bb0e2 Merge feature/title: keep both ideas in the title
|\  
| * 1670ef3 Rename notes title
* | 2117d1a Change title on main
|/  
* 1e3e254 Add quiz question 1
* fb1523a Ignore cache files and .env
MarkerMeaning
<<<<<<< HEADStart of your current branch's version
=======Divider
>>>>>>> feature/titleEnd of the incoming branch's version
  • Edit the file so it reads exactly as it should, and delete all three marker lines.
  • git add the file, then git commit to finish the merge. To give up instead, run git merge --abort.
  • Editors such as VS Code show buttons: Accept Current, Accept Incoming, Accept Both.

3. Rebase for a straight history

Real terminal output (captured when this guide was built)
$ git log --oneline --graph --all -3
* e0492ac Add glossary
| * 6478e23 Add quiz question 2
|/  
*   14bb0e2 Merge feature/title: keep both ideas in the title
|\
$ git switch feature/glossary
Switched to branch 'feature/glossary'
$ git rebase main
Rebasing (1/1)

Successfully rebased and updated refs/heads/feature/glossary.
$ git log --oneline --graph -3
* 209b3bc Add glossary
* 6478e23 Add quiz question 2
*   14bb0e2 Merge feature/title: keep both ideas in the title
|\
$ git switch main && git merge --ff-only feature/glossary
Updating 6478e23..209b3bc
Fast-forward
 glossary.md | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 glossary.md
Switched to branch 'main'
Careful. Golden rule: rebase only your own branches that nobody else has pulled. Rebasing rewrites commit IDs; never rebase main or a shared branch.

4. Merge or rebase?

MergeRebase
HistoryKeeps exactly what happened, with merge commitsStraight line, easier to read
SafetyNever rewrites commitsRewrites your branch's commits
Use whenJoining shared branches, finishing a pull requestUpdating your own feature branch with the latest main

On GitHub you can choose Create a merge commit, Squash and merge (one commit per pull request) or Rebase and merge for each pull request.

5. Stash unfinished work

Real terminal output (captured when this guide was built)
$ echo 'half-written idea' >> glossary.md
$ git stash push -m "glossary draft"
Saved working directory and index state On main: glossary draft
$ git status --short
$ git stash list
stash@{0}: On main: glossary draft
$ git stash pop
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   glossary.md

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (a9804dbe10f8ba3363df232790ddcdfe5accab07)
$ git status --short
 M glossary.md
$ git restore glossary.md

6. Branch naming that teams like

  • feature/signup-otp, fix/cart-total-rounding, docs/readme-setup.
  • Lowercase, hyphens, short. Include a ticket number if your team uses one: fix/PAY-142-refund-status.
  • Delete branches after merging: git branch -d name locally; GitHub can delete them automatically.

Common mistakes and fixes

MistakeFix
Working directly on mainCreate a branch for every change and merge through a pull request.
Leaving conflict markers in the fileSearch for <<<<<<< before committing; tests should fail if markers remain.
Rebasing a branch others useMerge instead, or agree with the team first.

Practice

  1. Create two branches that change the same line, merge them, and resolve the conflict.
  2. Rebase a feature branch on main and compare git log --graph before and after.
  3. Stash a half-finished change, fix something on main, then pop the stash.

Quick check

When does Git do a fast-forward merge?

When the target branch has no new commits since the feature branch started, so Git just moves the pointer.

How do you finish a merge after fixing a conflict?

git add the fixed files, then git commit (or git merge --abort to cancel).

What is the golden rule of rebasing?

Never rebase commits that other people have already pulled, such as main or shared branches.

What does git stash do?

It shelves uncommitted changes so the working tree is clean; git stash pop brings them back.

Go further (official sources)

Git & GitHub Complete Guide › Lesson 5 of 8 · about 25 minutes
Lesson 5

GitHub collaboration: remotes, push and pull, forks, pull requests, reviews and issues

Connect a local repository to GitHub, push, fetch and pull with real output, contribute through forks and pull requests, review code, track work with issues and Projects, and protect main with rulesets.

Checked against official sources in November 2026. Lessons build on each other.
In plain words. GitHub is the shared office. Push is taking your finished pages to the office; fetch is checking what colleagues left; a pull request is asking "please review my pages before we put them in the master copy".

Key ideas

Remote / originA named link to the GitHub copy of your repository.
push / fetch / pullSend commits up; download others' commits; download and merge into your branch.
ForkYour own copy of someone else's repository, used to propose changes to projects you cannot write to.
Pull request (PR)A request to merge one branch into another, with discussion, reviews and checks.
IssueA tracked task, bug or idea, which a PR can close ("Fixes #12").
Ruleset / branch protectionRules such as "main needs one approving review and passing checks".

How it works

1. Push to GitHub

After creating an empty repository on GitHub, add it as origin and push. A local bare repository stands in for GitHub here so you can see real output; with GitHub the URL looks like [email protected]:you/notes.git.

Real terminal output (captured when this guide was built)
$ git remote add origin ../github/notes.git
$ git remote -v
origin	../github/notes.git (fetch)
origin	../github/notes.git (push)
$ git push -u origin main
branch 'main' set up to track 'origin/main'.
To ../github/notes.git
 * [new branch]      main -> main
$ git branch -vv
* main 209b3bc [origin/main] Add glossary

2. Get a teammate's work: fetch, then pull

Real terminal output (captured when this guide was built)
$ git clone -q github/notes.git ravi && echo cloned
cloned
$ git config user.name "Ravi Teammate" && git config user.email [email protected] && echo 'Q3: What is a remote?' >> quiz.md && git commit -q -am "Add quiz question 3" && git push -q && git log --oneline -1
addeeb7 Add quiz question 3
$ git fetch
From ../github/notes
   209b3bc..addeeb7  main       -> origin/main
$ git status -sb
## main...origin/main [behind 1]
$ git log --oneline main..origin/main
addeeb7 Add quiz question 3
$ git pull --ff-only
Updating 209b3bc..addeeb7
Fast-forward
 quiz.md | 1 +
 1 file changed, 1 insertion(+)

git fetch downloads safely without changing your files; git status -sb shows you are behind; git pull --ff-only updates only if no merge is needed, which avoids surprise merge commits.

3. The pull request workflow

  1. Create a branch: git switch -c fix/typo-in-readme.
  2. Commit your change and push the branch: git push -u origin fix/typo-in-readme.
  3. On GitHub select Compare & pull request (or run gh pr create --fill). Write what changed, why, and how you tested it. Link the issue with Fixes #12.
  4. Reviewers comment line by line, suggest changes, then Approve or Request changes. Automated checks (GitHub Actions) run on every push.
  5. Push more commits to the same branch to address feedback; the PR updates automatically.
  6. Merge with the method your team uses, delete the branch, and run git switch main && git pull.

4. Contribute to someone else's project

  1. Select Fork on the project's GitHub page to make your copy.
  2. Clone your fork, and add the original as upstream: git remote add upstream https://github.com/owner/project.git.
  3. Keep in sync: git fetch upstream then git merge upstream/main (or use Sync fork on GitHub).
  4. Branch, commit, push to your fork, and open a pull request to the original repository. Read its CONTRIBUTING.md first.

5. Good reviews and good pull requests

AuthorReviewer
Small PRs (under ~300 lines changed) with a clear titleReview within a day; start with the description and tests
Explain why, link the issue, add screenshots for UIAsk questions rather than demand; separate must-fix from nice-to-have
Run tests and lint before askingUse suggested changes for small fixes the author can accept in one click

6. Issues, Projects and protecting main

  • Issues: one per bug or task, with labels (bug, enhancement, good first issue) and an assignee. Templates help reporters give the right details.
  • Projects: boards and tables that track issues and PRs across repositories, with custom fields such as priority and sprint.
  • Rulesets (Settings › Rules › Rulesets) or branch protection: require pull requests, at least one approval, passing status checks and no force pushes on main.
  • CODEOWNERS: a file that automatically requests reviews from the right people for each folder.

Common mistakes and fixes

MistakeFix
git pull creating messy merge commitsFetch first, or use git pull --ff-only; rebase your own branch on main when needed.
Huge pull requestsSplit work into small PRs that each do one thing.
Pushing directly to mainProtect main with a ruleset that requires pull requests and checks.

Practice

  1. Push a project to GitHub and open a pull request from a branch, even if you review it yourself.
  2. Fork a public repository, sync it with upstream, and open a small documentation PR.
  3. Create a ruleset on your own repository that requires a pull request for main.

Quick check

What is the difference between fetch and pull?

fetch downloads commits without changing your files; pull fetches and then merges (or rebases) into your branch.

Why add an upstream remote to a fork?

To fetch new commits from the original project and keep your fork in sync.

What does "Fixes #12" in a PR description do?

It links the PR to issue 12 and closes the issue when the PR is merged into the default branch.

Go further (official sources)

Git & GitHub Complete Guide › Lesson 6 of 8 · about 20 minutes
Lesson 6

Undo anything safely: amend, reset, revert, reflog and leaked secrets

Fix the last commit message, take back a commit you have not shared, undo a commit that is already on GitHub, recover "lost" work with the reflog, and what to do when a password is committed.

Checked against official sources in November 2026. Lessons build on each other.
In plain words. Git almost never loses work. Before you share commits, you can rewrite them freely. After you share them, you add a new commit that undoes the old one, so nobody's copy breaks.

Key ideas

git commit --amendReplaces the last commit (message or content). Only for commits not yet pushed.
git reset --soft / --mixed / --hardMoves the branch back; soft keeps changes staged, mixed keeps them in files, hard discards them.
git revertCreates a new commit that undoes an earlier one. Safe for shared history.
git reflogGit's diary of where HEAD has been; finds commits after a bad reset.
Force pushOverwrites the remote branch. Use --force-with-lease, and never on shared branches.

How it works

1. Which undo do I need?

SituationCommandSafe after push?
Typo in the last commit messagegit commit --amend -m "..."No
Forgot a file in the last commitgit add file && git commit --amend --no-editNo
Undo the last commit but keep the workgit reset --soft HEAD~1No
Undo a commit that is on GitHubgit revert <commit>Yes
Get back a commit after a bad resetgit reflog, then git reset --hard HEAD@{n}Local fix
Discard all local changesgit restore . (or git reset --hard)Local only; cannot be undone

2. Fix the last commit message

Real terminal output (captured when this guide was built)
$ echo 'tag = a name for one commit' >> glossary.md && git commit -q -am "Add tag defnition"
$ git log --oneline -1
dbb1203 Add tag defnition
$ git commit --amend -q -m "Add tag definition"
$ git log --oneline -1
7800ea1 Add tag definition

3. Reset: soft, mixed and hard

Real terminal output (captured when this guide was built)
$ echo 'temp line' >> quiz.md && git commit -q -am "Temporary commit"
$ git log --oneline -2
e528718 Temporary commit
7800ea1 Add tag definition
$ git reset --soft HEAD~1
$ git status --short
M  quiz.md
$ git reset --mixed HEAD
Unstaged changes after reset:
M	quiz.md
$ git status --short
 M quiz.md
$ git restore quiz.md && git status --short && echo clean
clean
  • --soft: the commit is gone, its changes stay staged.
  • --mixed (default): changes stay in your files but are unstaged.
  • --hard: changes are discarded. Check git status and git stash first.

4. Undo a pushed commit with revert

Real terminal output (captured when this guide was built)
$ echo 'wrong fact: git is a GitHub product' >> glossary.md && git commit -q -am "Add a wrong fact" && git push -q
$ git revert --no-edit HEAD
[main 1ee8249] Revert "Add a wrong fact"
 Date: Mon Nov 2 10:37:00 2026 +0530
 1 file changed, 1 deletion(-)
$ git log --oneline -3
1ee8249 Revert "Add a wrong fact"
d586c73 Add a wrong fact
7800ea1 Add tag definition

Revert adds a new commit, so teammates simply pull it. History stays honest: the mistake and its fix are both visible.

5. Recover "lost" commits with reflog

Real terminal output (captured when this guide was built)
$ git reset --hard HEAD~2
HEAD is now at 7800ea1 Add tag definition
$ git log --oneline -1
7800ea1 Add tag definition
$ git reflog -4
7800ea1 HEAD@{0}: reset: moving to HEAD~2
1ee8249 HEAD@{1}: revert: Revert "Add a wrong fact"
d586c73 HEAD@{2}: commit: Add a wrong fact
7800ea1 HEAD@{3}: reset: moving to HEAD
$ git reset --hard HEAD@{1}
HEAD is now at 1ee8249 Revert "Add a wrong fact"
$ git log --oneline -1
1ee8249 Revert "Add a wrong fact"
Good to know. The reflog is local and entries expire after weeks or months. Recover soon after the mistake.

6. You committed a password or API key

  1. Revoke and rotate the secret first (create a new key, delete the old one). Assume it is already copied.
  2. Remove it from the code, move it to an environment variable or secret store, and add the file to .gitignore.
  3. If it reached GitHub, clean the history with git filter-repo or the BFG tool, force-push with care, and ask collaborators to re-clone.
  4. Turn on GitHub secret scanning and push protection so pushes containing known secret formats are blocked.

Common mistakes and fixes

MistakeFix
Amending or resetting commits already pushed to a shared branchUse git revert instead.
git reset --hard with uncommitted work you wantedRun git status first; stash if unsure.
Thinking deleting a secret in a new commit is enoughIt stays in history; rotate it and clean history.
git push --force on mainProtect main; if you must overwrite your own branch, use --force-with-lease.

Practice

  1. Make a commit with a typo in the message and fix it with --amend.
  2. Make a commit, reset --soft, then recommit it differently.
  3. Do a reset --hard on purpose in a test repo and recover with reflog.

Quick check

Which undo is safe for commits already on GitHub?

git revert, because it adds a new commit instead of rewriting history.

What is the difference between reset --soft and --hard?

--soft keeps the changes staged; --hard discards them.

What is the first step after committing a secret?

Revoke and rotate the secret, because it may already be copied.

Go further (official sources)

Git & GitHub Complete Guide › Lesson 7 of 8 · about 22 minutes
Lesson 7

GitHub Actions, Pages, releases and security features

Automate tests with a GitHub Actions workflow, publish a free website with GitHub Pages, tag versions and publish releases, and switch on Dependabot, secret scanning and code scanning.

Checked against official sources in November 2026. Lessons build on each other.
In plain words. GitHub Actions is a robot that does a chore every time something happens, such as running your tests on every pull request. Pages is free hosting for a website straight from your repository. Releases are labelled boxes of a finished version.

Key ideas

WorkflowA YAML file in .github/workflows/ that says when to run (on) and what to do (jobs and steps).
RunnerThe machine that runs a job (GitHub-hosted Linux, Windows or macOS, or your own).
SecretsEncrypted values (API keys) available to workflows, never printed in logs.
GitHub PagesFree static website hosting from a repository, at username.github.io or a custom domain.
Tag and releaseA tag names one commit (v1.0); a release adds notes and downloadable files.
DependabotAlerts and pull requests that update vulnerable or outdated dependencies.

How it works

1. Your first workflow: test every pull request

.github/workflows/tests.yml
name: tests
on:
  pull_request:
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: pip install -r requirements.txt
      - run: pytest -q
  • Commit the file; the Actions tab shows each run and its logs.
  • Make the check required for main in your ruleset, so failing code cannot be merged.
  • Store keys in Settings › Secrets and variables › Actions and use them as ${{ secrets.API_KEY }}.
  • Pin actions to a version (or a commit SHA for third-party actions) and give workflows the least permissions they need.

2. Publish a website with GitHub Pages

  1. Put your site files (index.html and assets) in the repository, or build them with a workflow.
  2. Open Settings › Pages. Under Build and deployment, choose Deploy from a branch (main, root or /docs) or GitHub Actions.
  3. Wait a minute and open https://username.github.io/repository/.
  4. For your own domain, add it under Custom domain, create the DNS records your registrar needs, and tick Enforce HTTPS.
Careful. Pages sites are public unless your plan includes private Pages. Never publish private data or secrets on a Pages site.

3. Tags and releases

Real terminal output (captured when this guide was built)
$ git tag -a v1.0 -m "First complete set of notes"
$ git tag
v1.0
$ git show v1.0 --stat --format='%h %s'
tag v1.0
Tagger: Asha Learner <[email protected]>

First complete set of notes
1ee8249 Revert "Add a wrong fact"

 glossary.md | 1 -
 1 file changed, 1 deletion(-)
$ git push -q origin v1.0 && git ls-remote --tags origin
2ff02f39305b4137f405602cad721c3958d0c5e1	refs/tags/v1.0
1ee824981be5f41fefe948779fa71284523eb144	refs/tags/v1.0^{}

On GitHub open Releases, then Draft a new release, pick the tag, and select Generate release notes to list merged pull requests automatically. Use semantic versions: v1.4.2 means major.minor.patch.

4. Security features to switch on

FeatureWhat it doesWhere
Dependabot alerts and updatesWarns about vulnerable dependencies and opens update PRsSettings, Code security
Secret scanning and push protectionFinds committed tokens and blocks pushes with known secret patternsSettings, Code security
Code scanning (CodeQL)Finds security bugs in your code on every PRSecurity tab, Code scanning
Security policySECURITY.md tells people how to report vulnerabilitiesRepository root or .github/

5. Codespaces: a computer in the browser

Press . on a repository for a quick web editor, or open Code, Codespaces for a full cloud development environment with a terminal. A .devcontainer/devcontainer.json file sets up the same tools for everyone. Free personal usage is limited each month, so stop codespaces you are not using.

Common mistakes and fixes

MistakeFix
Printing secrets in workflow logsUse secrets, never echo them, and keep workflow permissions minimal.
Using unpinned third-party actionsPin to a version or a full commit SHA.
Expecting Pages to run a server or databasePages hosts static files only; use another service for back-end code.

Practice

  1. Add the tests workflow to a small Python project and make it fail, then pass.
  2. Publish a one-page portfolio with GitHub Pages.
  3. Turn on Dependabot alerts and secret scanning for your repositories.

Quick check

Where do workflow files live?

.github/workflows/ in the repository, as YAML files.

How do you stop failing code from being merged?

Make the workflow's status check required in the ruleset or branch protection for main.

What does push protection do?

Blocks pushes that contain known secret formats, such as API tokens.

Go further (official sources)

Git & GitHub Complete Guide › Lesson 8 of 8 · about 20 minutes
Lesson 8

GitHub with AI: Copilot, the coding agent, Claude Code and Codex

Use GitHub Copilot in your editor and on github.com, assign issues to the Copilot coding agent, ask @copilot to fix a pull request, review AI pull requests safely, and connect Claude Code or Codex to your repositories.

Checked against official sources in November 2026. Lessons build on each other.
In plain words. AI coding agents are fast junior developers who never get tired. They can open pull requests on their own, but a human still reviews, tests and decides what gets merged. Your repository's rules (tests, rulesets, AGENTS.md) are how you keep quality high.

Key ideas

GitHub CopilotGitHub's AI assistant: completions and chat in editors, chat on github.com, code review, CLI and a cloud coding agent.
Copilot coding agent (cloud agent)Works on an issue or request in its own environment using GitHub Actions and opens a pull request for review.
@copilot in a PRMention Copilot in a pull request comment to have it make the changes you ask for, including fixing failing checks.
Copilot code reviewAutomatic or requested AI review comments on pull requests.
AGENTS.md / CLAUDE.mdRepository files that tell AI agents how to build, test and follow your conventions.

How it works

1. Copilot in four places

WhereWhat you do
Editor (VS Code, JetBrains, Visual Studio)Accept suggestions with Tab; use chat to explain, refactor or write tests; agent mode edits several files
github.comChat about a repository, file or pull request; ask "what does this PR change?"
Pull requestsRequest a Copilot review; mention @copilot to make changes
TerminalCopilot CLI for commands and code tasks, including a security review command

Plans and limits change; check github.com/features/copilot for what your plan includes (premium requests are counted for heavier features).

2. Hand an issue to the coding agent

  1. Write the issue like a ticket for a new teammate: goal, files involved, acceptance criteria, how to test.
  2. Assign the issue to Copilot (or start a task from the agents panel). It works in its own environment powered by GitHub Actions and opens a draft pull request.
  3. By default its workflow runs wait for a person to approve them; repository admins can choose to skip that approval.
  4. Review the PR like any other: read the diff, run it, check tests. Comment @copilot please add a test for the empty-cart case to ask for changes.
  5. Merge only when checks pass and a human approves.
Good to know. Pull requests from forks are not supported for @copilot changes. Keep agent PRs small by writing small issues.

3. Claude Code and Codex with GitHub

  • Claude Code: works in your local clone or in cloud sessions (claude.ai/code) on repositories you connect; it commits on a branch and can open pull requests. The Claude GitHub app lets you mention @claude in issues and PRs where your organisation has set it up.
  • Codex: connect GitHub in Codex (desktop app, web, IDE or CLI); it works on a copy of the repository and proposes a pull request.
  • Both read repository instructions: CLAUDE.md for Claude Code and AGENTS.md for Codex and many other agents. Import AGENTS.md from CLAUDE.md to keep one source.
  • The Claude GitHub connector also lets Claude chat read your repositories and issues (Claude guide, Lesson 6).

4. Rules that keep AI pull requests safe

RuleWhy
Required status checks (tests, lint, CodeQL)Agents cannot merge broken or insecure code
At least one human approval; CODEOWNERS for sensitive foldersA person who knows the code decides
Least-privilege tokens and workflow permissionsAgents get only the access the task needs
Secret scanning with push protectionStops keys being committed by anyone, human or AI
Small issues with clear acceptance criteriaSmaller, reviewable pull requests

5. Show your work: a portfolio that gets interviews

  • Pin 3 to 5 repositories with clear READMEs: problem, approach, results, how to run.
  • Use issues and pull requests on your own projects; recruiters can see a real workflow.
  • Add a GitHub Actions badge and a live demo link (GitHub Pages).
  • Say which parts used AI and how you checked them; this is increasingly asked in interviews.

More on portfolios: SkillNavora lesson Portfolio, GitHub and resume for data roles.

Common mistakes and fixes

MistakeFix
Merging an agent PR because the description sounds rightRead the diff and run the tests yourself.
Vague issues assigned to an agentWrite acceptance criteria and test steps.
Giving an agent admin tokensUse least-privilege access and required reviews.

Practice

  1. Write an issue with acceptance criteria and assign it to an AI agent (Copilot, Claude Code or Codex); review its PR.
  2. Add AGENTS.md to a repository and import it from CLAUDE.md.
  3. Set a ruleset on main that requires passing checks and one approval.

Quick check

What does the Copilot coding agent produce?

A pull request (often a draft) for a human to review.

How do you ask Copilot to change an open pull request?

Mention @copilot in a PR comment with the change you want.

Which file do Codex and many agents read for repository rules?

AGENTS.md (Claude Code reads CLAUDE.md, which can import AGENTS.md).

Name two repository settings that keep AI PRs safe.

Required status checks and required human approval (also CODEOWNERS, secret scanning, least-privilege tokens).

Go further (official sources)

Refer & earn