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.
Contents
- 1. How Git works: snapshots, commits, branches and the three areas
- 2. Set up Git and GitHub: install, identity, SSH keys, GitHub CLI and your first repository
- 3. The daily Git loop: status, diff, add, commit, log, .gitignore and restore
- 4. Branches, merging, conflicts, rebase and stash
- 5. GitHub collaboration: remotes, push and pull, forks, pull requests, reviews and issues
- 6. Undo anything safely: amend, reset, revert, reflog and leaked secrets
- 7. GitHub Actions, Pages, releases and security features
- 8. GitHub with AI: Copilot, the coding agent, Claude Code and Codex
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.
Key ideas
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
| Area | What it is | Commands that move things |
|---|---|---|
| Working tree | Your files on disk | edit files; git restore to undo edits |
| Staging area | Changes chosen for the next commit | git add to stage; git restore --staged to unstage |
| Repository | Saved commits in .git | git 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.
$ 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
5e9b349eb22b7a59f77c79d033ec8e6a0a593b654. Branches are just pointers
mainis 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
| Mistake | Fix |
|---|---|
| Thinking GitHub and Git are the same | Git runs on your computer and works offline; GitHub hosts copies and adds collaboration tools. |
| Being afraid of branches | They are just pointers; create one for every change. |
| Committing everything at the end of the week | Commit small, logical steps with clear messages. |
Practice
- Draw the three areas on paper and write which command moves a change between each.
- In a test repository run git cat-file -p HEAD and find the tree, author and message.
- 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)
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.
Key ideas
How it works
1. Install Git
| System | How |
|---|---|
| Windows | Download 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. |
| macOS | Run git --version; macOS offers to install the Command Line Tools. Or brew install git. |
| Linux | sudo apt install git (Ubuntu/Debian) or sudo dnf install git (Fedora). |
Check it worked:
$ git --version
git version 2.43.02. Tell Git who you are
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 from3. Create your GitHub account safely
- Sign up at github.com with a professional username (it appears in your portfolio links).
- Turn on two-factor authentication: . Use an authenticator app or a passkey, and save the recovery codes.
- Add a profile photo, bio and a profile README (a repository named exactly like your username).
4. Connect with SSH (recommended)
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
# 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 --oneline6. Your first repository from scratch
Here is a real first session: create a folder, start Git, and see what status reports.
$ 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)$ 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 titleTo 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
| Mistake | Fix |
|---|---|
| Commits show the wrong name or email | Set user.name and user.email globally, and fix a single repository with git config (without --global). |
| Typing your GitHub password in the terminal | GitHub does not accept account passwords for Git; use SSH, the GitHub CLI, or a token via the credential manager. |
| Sharing the private SSH key | Only the .pub file is shared. If a private key leaks, delete it on GitHub and create a new one. |
Practice
- Install Git, set your name and email, and run git config --list --show-origin.
- Create an SSH key, add it to GitHub and run ssh -T [email protected].
- 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)
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.
Key ideas
How it works
1. A real day of work
Edit a file, create another, check, stage, commit and read history:
$ 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 commitwithout -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.
$ 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# .gitignore for a Python or data project
.env
*.key
__pycache__/
.venv/
.ipynb_checkpoints/
data/raw/ # large or private data
*.log
.DS_Store4. Undo edits safely
$ 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 to | Command |
|---|---|
| Throw away unstaged edits in a file | git restore file |
| Unstage a file but keep the edits | git restore --staged file |
| See what you are about to commit | git diff --staged |
| Stage only parts of a file | git add -p file (answer y or n per change) |
5. Read history like a pro
$ 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(+)--authorfilters by person,-S "text"finds commits that added or removed that text.git blameshows which commit last changed each line.git showshows one commit's message and changes.
Common mistakes and fixes
| Mistake | Fix |
|---|---|
| git add . without looking | Run 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 file | Add it to .gitignore before the first commit; if it leaked, rotate the secret. |
Practice
- Make three small changes and commit them as three separate commits with clear messages.
- Create a .gitignore, add a fake .env and confirm git status ignores it.
- 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)
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.
Key ideas
How it works
1. Branch and fast-forward merge
$ 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:
$ 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| Marker | Meaning |
|---|---|
<<<<<<< HEAD | Start of your current branch's version |
======= | Divider |
>>>>>>> feature/title | End of the incoming branch's version |
- Edit the file so it reads exactly as it should, and delete all three marker lines.
git addthe file, thengit committo finish the merge. To give up instead, rungit merge --abort.- Editors such as VS Code show buttons: Accept Current, Accept Incoming, Accept Both.
3. Rebase for a straight history
$ 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)
[KSuccessfully 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'4. Merge or rebase?
| Merge | Rebase | |
|---|---|---|
| History | Keeps exactly what happened, with merge commits | Straight line, easier to read |
| Safety | Never rewrites commits | Rewrites your branch's commits |
| Use when | Joining shared branches, finishing a pull request | Updating 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
$ 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.md6. 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 namelocally; GitHub can delete them automatically.
Common mistakes and fixes
| Mistake | Fix |
|---|---|
| Working directly on main | Create a branch for every change and merge through a pull request. |
| Leaving conflict markers in the file | Search for <<<<<<< before committing; tests should fail if markers remain. |
| Rebasing a branch others use | Merge instead, or agree with the team first. |
Practice
- Create two branches that change the same line, merge them, and resolve the conflict.
- Rebase a feature branch on main and compare git log --graph before and after.
- 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)
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.
Key ideas
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.
$ 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 glossary2. Get a teammate's work: fetch, then pull
$ 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
- Create a branch:
git switch -c fix/typo-in-readme. - Commit your change and push the branch:
git push -u origin fix/typo-in-readme. - 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. - Reviewers comment line by line, suggest changes, then Approve or Request changes. Automated checks (GitHub Actions) run on every push.
- Push more commits to the same branch to address feedback; the PR updates automatically.
- Merge with the method your team uses, delete the branch, and run
git switch main && git pull.
4. Contribute to someone else's project
- Select Fork on the project's GitHub page to make your copy.
- Clone your fork, and add the original as
upstream:git remote add upstream https://github.com/owner/project.git. - Keep in sync:
git fetch upstreamthengit merge upstream/main(or use Sync fork on GitHub). - 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
| Author | Reviewer |
|---|---|
| Small PRs (under ~300 lines changed) with a clear title | Review within a day; start with the description and tests |
| Explain why, link the issue, add screenshots for UI | Ask questions rather than demand; separate must-fix from nice-to-have |
| Run tests and lint before asking | Use 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 () 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
| Mistake | Fix |
|---|---|
| git pull creating messy merge commits | Fetch first, or use git pull --ff-only; rebase your own branch on main when needed. |
| Huge pull requests | Split work into small PRs that each do one thing. |
| Pushing directly to main | Protect main with a ruleset that requires pull requests and checks. |
Practice
- Push a project to GitHub and open a pull request from a branch, even if you review it yourself.
- Fork a public repository, sync it with upstream, and open a small documentation PR.
- 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)
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.
Key ideas
How it works
1. Which undo do I need?
| Situation | Command | Safe after push? |
|---|---|---|
| Typo in the last commit message | git commit --amend -m "..." | No |
| Forgot a file in the last commit | git add file && git commit --amend --no-edit | No |
| Undo the last commit but keep the work | git reset --soft HEAD~1 | No |
| Undo a commit that is on GitHub | git revert <commit> | Yes |
| Get back a commit after a bad reset | git reflog, then git reset --hard HEAD@{n} | Local fix |
| Discard all local changes | git restore . (or git reset --hard) | Local only; cannot be undone |
2. Fix the last commit message
$ 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 definition3. Reset: soft, mixed and hard
$ 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
$ 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 definitionRevert 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
$ 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"6. You committed a password or API key
- Revoke and rotate the secret first (create a new key, delete the old one). Assume it is already copied.
- Remove it from the code, move it to an environment variable or secret store, and add the file to .gitignore.
- If it reached GitHub, clean the history with
git filter-repoor the BFG tool, force-push with care, and ask collaborators to re-clone. - Turn on GitHub secret scanning and push protection so pushes containing known secret formats are blocked.
Common mistakes and fixes
| Mistake | Fix |
|---|---|
| Amending or resetting commits already pushed to a shared branch | Use git revert instead. |
| git reset --hard with uncommitted work you wanted | Run git status first; stash if unsure. |
| Thinking deleting a secret in a new commit is enough | It stays in history; rotate it and clean history. |
| git push --force on main | Protect main; if you must overwrite your own branch, use --force-with-lease. |
Practice
- Make a commit with a typo in the message and fix it with --amend.
- Make a commit, reset --soft, then recommit it differently.
- 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)
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.
Key ideas
How it works
1. Your first workflow: test every pull request
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 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
- Put your site files (index.html and assets) in the repository, or build them with a workflow.
- Open . Under Build and deployment, choose Deploy from a branch (main, root or /docs) or GitHub Actions.
- Wait a minute and open
https://username.github.io/repository/. - For your own domain, add it under Custom domain, create the DNS records your registrar needs, and tick Enforce HTTPS.
3. Tags and releases
$ 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
| Feature | What it does | Where |
|---|---|---|
| Dependabot alerts and updates | Warns about vulnerable dependencies and opens update PRs | Settings, Code security |
| Secret scanning and push protection | Finds committed tokens and blocks pushes with known secret patterns | Settings, Code security |
| Code scanning (CodeQL) | Finds security bugs in your code on every PR | Security tab, Code scanning |
| Security policy | SECURITY.md tells people how to report vulnerabilities | Repository 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
| Mistake | Fix |
|---|---|
| Printing secrets in workflow logs | Use secrets, never echo them, and keep workflow permissions minimal. |
| Using unpinned third-party actions | Pin to a version or a full commit SHA. |
| Expecting Pages to run a server or database | Pages hosts static files only; use another service for back-end code. |
Practice
- Add the tests workflow to a small Python project and make it fail, then pass.
- Publish a one-page portfolio with GitHub Pages.
- 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)
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.
Key ideas
How it works
1. Copilot in four places
| Where | What 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.com | Chat about a repository, file or pull request; ask "what does this PR change?" |
| Pull requests | Request a Copilot review; mention @copilot to make changes |
| Terminal | Copilot 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
- Write the issue like a ticket for a new teammate: goal, files involved, acceptance criteria, how to test.
- 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.
- By default its workflow runs wait for a person to approve them; repository admins can choose to skip that approval.
- Review the PR like any other: read the diff, run it, check tests. Comment
@copilot please add a test for the empty-cart caseto ask for changes. - Merge only when checks pass and a human approves.
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
@claudein 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.mdfor Claude Code andAGENTS.mdfor 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
| Rule | Why |
|---|---|
| Required status checks (tests, lint, CodeQL) | Agents cannot merge broken or insecure code |
| At least one human approval; CODEOWNERS for sensitive folders | A person who knows the code decides |
| Least-privilege tokens and workflow permissions | Agents get only the access the task needs |
| Secret scanning with push protection | Stops keys being committed by anyone, human or AI |
| Small issues with clear acceptance criteria | Smaller, 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
| Mistake | Fix |
|---|---|
| Merging an agent PR because the description sounds right | Read the diff and run the tests yourself. |
| Vague issues assigned to an agent | Write acceptance criteria and test steps. |
| Giving an agent admin tokens | Use least-privilege access and required reviews. |
Practice
- Write an issue with acceptance criteria and assign it to an AI agent (Copilot, Claude Code or Codex); review its PR.
- Add AGENTS.md to a repository and import it from CLAUDE.md.
- 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).