What is Git?
What version control is, how Git was born, how it differs from GitHub, and why virtually every software team uses it.
The problem: final_project_v3_really_final.docx
It has probably happened to you. You work on a document, make a copy “just in case”, then another one, and end up with a folder like this:
thesis.docx
thesis_v2.docx
thesis_v2_fixed.docx
thesis_final.docx
thesis_final_REALLY.docx
thesis_final_REALLY_with_anas_changes.docxNow imagine the same thing with the code of an app that five people work on at the same time. Which version is the good one? Who changed what? How do I go back to how it was on Tuesday, before everything broke?
That is what version control is for.
What is version control?
A version control system keeps the complete history of a project: every change, who made it, when and why. With it you can:
- Go back: restore any file (or the whole project) to how it was at any point in time.
- Compare versions and see exactly which lines changed.
- Work in parallel on several ideas without them getting in each other’s way.
- Collaborate with other people and combine everyone’s work in an orderly way.
- Know who and why made each change, even years later.
Instead of copying folders, you tell the system “save a snapshot of how everything looks right now” and give it a description. Each of those snapshots is called a commit.
What is Git?
Git is the most widely used version control system in the world. It was created in 2005 by Linus Torvalds, the creator of Linux, because he needed a fast and reliable tool to coordinate the thousands of people contributing to the Linux kernel.
Today it is used by everyone from students on their first project to companies like Google, Microsoft, Netflix and Shopify. If you are going to work in software, Git is not optional: it is part of the daily routine.
Centralized vs. distributed
The first version control systems (such as SVN) were centralized: the history lived on a single server and each person only had the latest version. If the server went down, nobody could save changes.
Git is distributed: every person has a full copy of the repository, with its entire history. That means:
- You can commit, browse the history and create branches without internet.
- Almost every operation is instant, because it happens on your computer.
- If the server is lost, any copy can be used to restore it.
| Centralized (SVN) | Distributed (Git) | |
|---|---|---|
| Where is the history? | Only on the server | On every computer |
| Does it work offline? | Barely | Almost entirely |
| Speed | Depends on the network | Local, very fast |
Git is not GitHub
This is the most common confusion when starting out:
- Git is the program you install on your computer, which keeps the history of your project.
- GitHub, GitLab and Bitbucket are online services that host copies of Git repositories so you can share them, review them and collaborate.
An analogy
Git is like the camera that takes the pictures of your project. GitHub is like a cloud album where you share them with your team. You can use the camera without the album, but the album is useless without the camera.
In this course you will first learn Git on its own, on your computer, and in module 5 you will connect it to GitHub to work as a team.
Vocabulary you will use throughout the course
| Term | Meaning |
|---|---|
| Repository (repo) | Your project folder plus its whole history |
| Commit | A saved snapshot of the project, with a message, author and date |
| Branch | An independent line of work inside the repo |
| Merge | Combining the work of one branch into another |
| Remote | A copy of the repo somewhere else, for example on GitHub |
| Push / Pull | Send your commits to the remote / bring the remote’s commits to you |
Don’t worry if it isn’t clear yet: each term has its own lesson.
Your practice terminal
In every lesson you will find a terminal like this one. It runs inside your browser with a real Git simulated in memory: you can type commands without fear, nothing leaves your computer, and the Reset button makes it brand new again.
Type git --version and press Enter. Then try help to see the available commands.
Tip
Learning Git is like learning to drive: reading helps, but practicing is what makes you learn. Type each command yourself instead of just reading it.
Test what you learned
Challenge
Before moving on, think of a project of your own (homework, a website, a long document) and answer:
- Have you ever lost work, or not known which version was the good one?
- What would you like to be able to “undo” or compare in that project?
Then, in the terminal, type git help and read the command groups: by the end of the course you will have used almost all of them.
See a sample answer
On a personal website, Git would let you go back to the previous design if you don’t like the new one, see what you changed right before the menu broke, and try out an idea on a branch without touching the published version.
The git help commands are grouped by task: starting a repository (init, clone), working on a change (add, restore), examining the history (status, log, diff), branches and history (branch, merge, commit…) and collaborating (push, pull, fetch).
