Git & GitHub
Commits, the index, diffs, Git's objects and hashes, branches, merges, conflicts, rebasing, remotes and pull requests, with Git's ideas built in Python.
- Level
- Intermediate
- Time
- About 20 hours
- Modules
- 5
- Lessons
- 15
- Exercises
- 45
Git is the version control system behind almost every software project, and GitHub is where most of them are shared. This course teaches the commands you will use every day, from your first commit to branches, merges, rebases, pull requests and automated checks, and explains what each one really does.
Every lesson's exercises are small Python programs that model Git exactly: you compute the same object ids as git hash-object, produce git status codes, diffs and blame, find merge bases, resolve conflicts, replay rebases, decide which pushes a server accepts and which files .gitignore hides. Understanding the model is what makes Git predictable.
What you will learn
- Record work with commits, the index and good messages
- Inspect changes with diff, log and blame
- Explain blobs, trees, commits, refs and how ids are computed
- Branch, merge, resolve conflicts and rebase with confidence
- Undo mistakes with restore, reset, revert and the reflog
- Collaborate with remotes, pull requests, conventional commits, .gitignore and GitHub Actions
Skills you will gain
- Everyday Git commands
- Reading and resolving diffs and conflicts
- Branching and merging strategies
- Rewriting and recovering history safely
- Collaboration on GitHub
Before you start
- Python: strings, lists, dictionaries, sets and functions (the Python course)
- Using a terminal to run commands helps (the Developer Tools course)
- Git installed on your computer to try the commands, though the exercises run in the browser
Where it is used
- Keeping the history of any software project
- Team development with branches and pull requests
- Releasing software with tags and semantic versions
- Automating checks with GitHub Actions
Modules
Module 1: Getting started
Repositories and commits, the working tree, index and HEAD, and how to see what changed with diff, log and blame.
- 1
Version control and your first repository Intermediate
Why every project keeps its history in version control, what a Git repository is, and the first commands: configure Git, create a repository, check its status and look at the history.
- 2
Staging and committing Intermediate
Git has three places for your files: the working tree, the staging area and the last commit. Choose exactly what goes into each commit with git add, record it with git commit, and read the codes that git status prints.
- 3
Viewing changes: diff, log and blame Intermediate
See exactly what changed: compare versions line by line with git diff, read the history with git log and git show, and find who last changed each line with git blame. Learn the longest-common-subsequence idea behind every diff.
Module 2: Inside Git
The object database: blobs and hashes, trees and commits, and refs, HEAD and revision expressions.
- 1
Inside Git: objects and hashes Intermediate
Git is a content-addressed store: every file version is saved as a blob named by the SHA-1 hash of its contents. Compute blob ids exactly as Git does, see why identical files are stored once, and use short hashes safely.
- 2
Inside Git: trees and commits Intermediate
See how Git builds a snapshot from objects: trees list names and point to blobs and subtrees, and commits point to a tree, their parents, an author and a message. Compute tree and commit ids and see why history cannot be changed silently.
- 3
Branches, HEAD and revision names Intermediate
Branches are just names pointing at commits, and HEAD says which one you are on. Learn how refs are stored, what a detached HEAD is, which branches contain a commit, and how to name commits with expressions such as HEAD~2 and main^2.
Module 3: Branching and merging
Working with branches, fast-forwards and three-way merges, and resolving conflicts.
- 1
Working with branches Intermediate
Use branches to develop features and fixes side by side without disturbing the main line. Create, list, switch and delete branches, follow naming rules, and see which branches are merged and which still have work of their own.
- 2
Merging Intermediate
Combine the work of two branches. Recognise when a merge is a fast-forward, find the merge base, and see how a three-way merge takes each change from whichever side made it, and where it must stop with a conflict.
- 3
Resolving merge conflicts Intermediate
When both branches change the same lines, Git marks the clash in the file and waits for you. Read conflict markers, decide what the result should be, finish the merge, and understand how a line-by-line three-way merge produces the markers.
Module 4: Changing history
Undoing changes with restore, reset, revert and the reflog; rebasing; and stashes, tags and semantic versions.
- 1
Undoing changes: restore, reset, revert and the reflog Intermediate
Fix mistakes at every stage: discard edits with git restore, unstage files, move a branch back with git reset in its three modes, undo a shared commit safely with git revert, amend the last commit, and recover "lost" commits from the reflog.
- 2
Rebasing Advanced
Move a branch's commits onto a new base to keep history linear. See which commits a rebase replays, rewrite commits with an interactive rebase (reword, squash, fixup, drop), handle conflicts commit by commit, and follow the golden rule of rebasing.
- 3
Stashing work and tagging releases Intermediate
Put unfinished work aside with git stash while you fix something urgent, and mark releases with tags. Use semantic versioning to name versions, compare them correctly, and describe any commit relative to the latest tag.
Module 5: Collaboration
Remotes, fetch, pull and push; pull requests and conventional commits; .gitignore and GitHub Actions.
- 1
Remotes: clone, fetch, pull and push Intermediate
Work with copies of a repository on GitHub and on teammates' computers. Clone a repository, fetch new commits, pull them into your branch, push your own, and understand ahead and behind counts and why pushes are rejected.
- 2
Pull requests and conventional commits Intermediate
Collaborate on GitHub through forks and pull requests: propose a branch, get it reviewed, and merge it. Write commit messages in the Conventional Commits format so that tools can generate changelogs and choose the next version automatically.
- 3
.gitignore and GitHub Actions Intermediate
Keep build output, logs and secrets out of the repository with .gitignore patterns, and automate tests and checks on every push and pull request with GitHub Actions workflows triggered by branch patterns.
Projects
- A mini Git in Python Write a small version control system in Python that stores real Git objects, so that its ids match git hash-object, and supports the everyday commands.
- A team workflow on GitHub Set up a small project on GitHub the way a professional team would, and use it for a full feature cycle with a partner (or two of your own accounts).
What to learn next
- Open-Source Contribution Licenses, reading a codebase you did not write, issues and bug reports, pull requests, code review and style, and a first contribution to StepVioz.
- Developer Tools The terminal, gcc and its warnings, error messages, header files, make, gdb, testing and Git: the tools around the code.