Skip to content
Open Sourcebeginner

What is Git?

Updated Nov 30, 20264 min readBased on official documentation
What is Git?

In short

Git is a free tool that records the history of your files so you can see past versions, compare changes, and go back when something breaks. It is a distributed version control system, meaning every copy of a project holds the full history. Developers use it to track code and to work together.

Why version control exists

Imagine you are writing a document. You save a copy called final.doc, then another called final-v2.doc, then final-really-final.doc. This habit is common, but it is easy to lose track of which file holds which change. Version control is a system that solves this problem. It records changes to a file or a set of files over time, so you can bring back a specific version later.

Software developers usually store source code in version control, but the same idea works for almost any file. Designers who keep every version of an image or a layout get the same benefits.

A good version control system lets you go back to an earlier state of one file or the whole project. It lets you compare changes made at different times. It also shows who last changed a line, which helps when a bug appears and you need to know where it came from. If you make a mistake or delete something by accident, you can recover it. Most of this comes with very little extra work from you.

Older approaches and their limits

Many people start with a simple method: they copy files into another folder, sometimes with a date in the folder name. This is easy, but it is risky. It is simple to forget which folder you are in and overwrite the wrong file.

To fix this, programmers built local version control systems. These tools keep a small database on your own computer that stores every change to the files under their control. One well-known example, RCS, stored the differences between file versions and rebuilt any older version by applying those differences in order.

Teams soon needed to work together, so centralized version control systems came next. Tools such as CVS, Subversion and Perforce keep all versioned files on one server. Each developer, called a client, checks out files from that central place. This model gave teams a shared view of the project and let administrators control who could change what.

The weakness of this design is the central server. It is a single point of failure. If the server goes down, nobody can save versioned changes until it returns. If its disk breaks and there are no backups, the project history can be lost, except for whatever copies people still hold on their own machines.

How Git works

Git belongs to a third group called distributed version control systems. Other members of this group include Mercurial and Darcs. In a distributed system, a client does not just take the latest snapshot of the files. It copies the whole repository, including its full history. A repository is the database that stores a project and its changes.

Because every copy holds the full history, any copy can restore a damaged server. Each clone is effectively a complete backup. Developers can also work with several remote repositories at once. This makes it possible to set up workflows, such as hierarchical models, that are hard to do with a centralized system.

The official documentation describes these ideas in its opening chapter. If you want to read the original, start with the Getting Started section of the Pro Git book.

A simple way to start

Once Git is installed, you can create a repository in an empty folder with a single command:

git init

Then you can save a snapshot of your work. Add files to the staging area, then record the change with a message:

git add notes.txt
git commit -m "Add first draft"

Later, git log shows the list of saved changes, and git diff shows what has changed since the last commit. Each step is a small, clear action, which makes it a good place to learn the habit of saving versions often.

Common mistakes for beginners

New users often expect Git to back up their files automatically. It does not. Git only saves what you commit. Changes that are not committed can still be lost, so commit your work regularly.

Another common mistake is storing large binary files, such as videos, in a repository without thinking about it. Git is built mainly for text, such as source code, and it works best that way.

Finally, remember that a clone is only a full backup if it is up to date. Push your commits to a remote repository so that the history exists in more than one place.

Git is not the only option. Subversion is a centralized system that many teams still use. Mercurial is a distributed system with a similar design. The choice depends on your team, your tools and your hosting setup.

If you are new to the wider community around these tools, our guide to open source explains how many projects share their code. You can also read about forking projects to see how contributors often start their own copies of a repository.

FAQ

Is Git the same as GitHub?

No. Git is the version control tool that runs on your computer. GitHub is a website that hosts Git repositories and adds features for sharing and reviewing code.

Do I need a server to use Git?

No. Git works on a single computer without any server. A server or remote repository is useful when you want to share work with other people or keep an extra backup.

What is the difference between a centralized and a distributed system?

In a centralized system, one server holds the full history and clients only get the latest files. In a distributed system like Git, every clone holds the full history, so any copy can restore the project.

Can Git track files other than code?

Yes, Git can track most file types. It is most effective with text files, because it can show line-by-line differences for them easily.

Sources

This page is based on the official documentation below. Read it for full detail.

Git — official documentation ↗
blozhikDeveloper news from across the web, explained. Every story links to its original sources.