Git Show archive.org snapshot is our version control system. This lesson covers the everyday moves — committing, branching, merging, working with a remote — and the habits that make your history pleasant to review.
Important
Work on this lesson in
teachermode.
Learning goals
- You can explain where a change lives at each stage — working copy, staging area, local repository, remote — and how it moves between them.
- You can record work in a local repository: stage, commit, and inspect history and diffs.
- You can work with branches: create, switch and merge them, and explain what a fast-forward merge is.
- You can put uncommitted changes aside and get them back (stash).
- You can synchronize with a remote repository over SSH, and explain the difference between fetching and pulling.
- You write commits a colleague can review: one change per commit, a subject line that says what and why.
- Your Git configuration follows our config example (identity, SSH key, default branch, pull behaviour).
- You can browse a repository's history in a viewer (
tigis our default) and create repositories and merge requests on code.makandra.de. - You have a GitHub account and know our rules for private accounts on work PCs.
Tip
Always clone repositories with SSH. Otherwise, you would have to send your git credentials to the remote server every time you interact with it.
Resources
Read what's new to you, skim what's familiar, skip what you already master. Stop when you can meet the learning goals.
Your agent can also generate an overview, a tutorial or an explanation for anything here, tailored to what you already know. Just ask.
Pick one introduction
- 📄 gittutorial Show archive.org snapshot — the official tutorial: repository, commits, branches, remotes
- ▶️ Git & GitHub Crash Course Show archive.org snapshot — freeCodeCamp, 1 hour
Go deeper
- 📘 Pro Git, chapters 2 "Git Basics" Show archive.org snapshot and 3 "Git Branching" Show archive.org snapshot — the free book; the best explanation of workspace, index and repository
- 🎮 Interactive Git visualization Show archive.org snapshot — an emulated Git shell that draws commits and branches as a graph; try any command
- 🎮 Learn Git Branching Show archive.org snapshot — guided levels on branching and merging
Our setup and conventions
- 📄 Configuring Git:
.gitconfig— our config example - 📄 How to Write a Git Commit Message Show archive.org snapshot — the seven rules for commits a colleague can review
- 📄 Using tig — our default history viewer
- 📄 Rules for private GitHub accounts — read before you use GitHub on your work PC (internal card, sign in to read)
Reference
- 📄 Atlassian Git Cheatsheet Show archive.org snapshot (PDF)
- 📄
Official documentation
Show archive.org snapshot
and
git help <command>
Exercises
Understanding git concepts
Try and explain:
- Why do we use Git at all?
- What is the "workspace"?
- What is the "index" or "staging area"?
- What is the "stash"?
- What is the difference between a local and a remote repository?
- What is a "Fast Forward"?
Play around on code.makandra.de
In an earlier lesson you built a searchable address book, in a directory of your exercises repository. Give it a repository of its own: you keep working on it in the next lessons, and it is a good excuse to click through the GitLab interface.
- Create a repository in your personal namespace (
/firstname.lastname), e.g.address-book. - Move the address book directory out of your
exercisesrepository and into a clone of the new one. - Add and commit the files
- Create a branch and make some small changes there
- Write the commit message as if a colleague had to review it: a subject that says what and why (see "How to Write a Git Commit Message" in the resources)
- Push changes to the server
- Make a merge request from the branch to your
main - Accept the merge request
- Look at the resulting history with
tig
Play around on github.com
- Sign up
- Create a repository in your personal namespace (
/username) - Add some files, push them
- Delete the repository when done
Important
Read our rules for private GitHub accounts (see Resources) before you sign up.