Git and Version Control

Learn Git from the very beginning: keep the history of your work, undo mistakes without fear, and collaborate with other people on GitHub. Every command in the series is typed on your own computer, and every output shown was produced by real Git.

10 modules27 hoursEN / 中文

How to study

Each module takes two to three hours. Read a section, then type the commands of its session in your own terminal and compare what you see with the output on the page. Module 1 shows you how to install Git and set it up.

The output on these pages was produced by the Git version named in each caption, with example names, dates and folders. Your names, dates, commit hashes and folders will differ, and other versions of Git word some messages a little differently; what the messages mean stays the same.

Every module ends with exercises with worked solutions and a short self-check quiz. Your progress is saved in this browser and shared by the English and Chinese editions.

The modules

Module 01
Why version control?
The problems version control solves, how Git differs from older tools, installing Git, and telling it who you are.
Available · 2 hours
Module 02
Your first repository
Create a repository, learn the working tree, staging area and repository, make focused commits and ignore files Git should not track.
Available · 3 hours
Module 03
History and undoing
Read history, compare versions, look at old versions safely, and undo mistakes at every stage.
Available · 3 hours
Module 04
Branches
Branches as movable labels, HEAD, switching between lines of work, and fast-forward and three-way merges.
Available · 3 hours
Module 05
Merge conflicts
Why conflicts happen, how to read conflict markers, and how to resolve, finish or abort a merge.
Available · 2 hours
Module 06
Remotes
Clone, fetch, pull and push with a remote repository, first on your own computer and then on GitHub.
Available · 3 hours
Module 07
Collaborating with pull requests
Feature branches, forks, pull requests, code review and keeping your work up to date with the team.
Available · 3 hours
Module 08
Rewriting history and recovering
Tidy history with rebase, squash and amend, follow the one rule about shared history, and rescue work with reflog.
Available · 3 hours
Module 09
How Git works inside
Blobs, trees, commits, hashes and refs: the few ideas that explain everything Git does.
Available · 2 hours
Module 10
Capstone: a team project
Two people, two clones and one shared repository build a small project from the first commit to a tagged release.
Available · 3 hours

Acknowledgements

This series was written for this site. For more depth it recommends, without copying from them, the free book Pro Git by Scott Chacon and Ben Straub, the official Git reference, GitHub Docs and, for extra practice with branches, Learn Git Branching.