Version control overview#

Our course material is in Git. All the open-source software we use is in Git. Linux is in Git. It’s the basis of modern software development. We’ll work on Git in detail later, but here are a few quick basics:

Repositories#

The core “unit” of Git is a repository. Repositories hold your code, along with all history. The online version of the repository is called a remote. Getting a copy of the repository locally is called cloning.

History#

The history of a Git repository is stored with it. Each stored point in time is called a commit. Git is a bit clever in how it stores history, so making lots of commits is fairly cheap. Multiple commits can share a parent, making the commit history look a bit like a tree (technically a graph, since you can also share parents, but we won’t worry about that too much yet).

You can create a moving “name” that points at a commit called a branch, or a stationary name called a tag (at least it should be stationary). One of the reasons for this is that all git commits are “named” by their SHA hash. Why not a nice, incrementing number? Because git is distributed.

Distributed#

Unlike older systems, every full git checkout is a complete, independent copy of the repository! You have all history locally. If you clone a remote repository, you could push to a different remote if you wished. If GitHub, GitLab, or whatever other hosting service you are using disappears tomorrow, you can simply push somewhere else and have all your history intact.

Hosted#

Services like GitHub, GitLab, and BitBucket host git remotes. They usually add web UI features that are not part of git, as well, like “pull requests/merge requests”, “issues”, and “forks”. This is stored as part of the hosting system and is not part of your git repository.

Version control quick intro#

In a terminal, you can clone a public repository. Let’s try cloning the packaging repo, a small Python library:

git clone https://github.com/pypa/packaging

Now enter the directory just created:

cd packaging

Verify nothing has changed and verify you are on the main branch:

git status

Make sure you are up to date (you should be if you just cloned it!)

git pull

Check the tags:

git tag

Switch to a recent release:

git checkout 21.3

Note that git is complaining because you are on a tag now, instead of a branch. That’s okay, we won’t be doing any development, we are just practicing. When you checkout a specific commit or tag, any tracked file in the repo is updated to match how the repository looked at that point in history, similar to a backup of your filesystem.

Go back to main:

git checkout main

Actually, what has changed since 21.3?

git log 21.3..main
git diff 21.3

We’ll go into git more later, but you should at least be comfortable consuming git repositories. Later we’ll work on contributing and collaborating.