Let's say you write code, or work on a book, or even just want to collect and update a set of text-based documents. You need some method of keeping track of changes, of being able to revert mistakes in the work, or branch in new directions; and you'll probably want some way of remotely backing up your work in case of fire, theft, or acts of a misbehaving computer. This is where version control systems (also known as VCS) come in handy. They save your work at certain points (commits) and can be reverted to earlier states; many VCS offer methods of branching so that you can – for example – work on a specific feature without interrupting someone else's work on another component. There are many version control systems on the market, but the most prominent in the public eye would be Git. Git is a distributed version control system, which means that it has a full copy of all of the code that exists on each user's computer, and users can pass patches and changes directly between each other rather than entirely relying on a centralized server.
Behind the scenes, git is an advanced program that is lightning fast when it comes to performing operations like staging work, committing changes, or swapping between branches. It's efficient at fetching information from remote repositories to help speed up a user's workflow. Unlike most VCS, git doesn't work by storing the changes that happen to each file. Instead, on every commit, git stores a snapshot of the current state of all files. If a file hasn't changed, rather than storing it again, it simply stores a reference to the last saved version of the file.
When you make a commit, git captures the snapshot and also takes a cryptographic hash – a series of complex mathematical operations on the data that produces a unique value – and uses the output of that as a reference to the commit, along with some metadata, such as the author. This snapshot sits on top of the rest of the snapshots/commits that you've taken, and in this way you can think of git snapshots as a series of changesets – operations that add or remove lines – that can be performed on your files to get them to an older or newer state.
We'll cover more on the higher-level use and commands of Git in Chapter 3, GitLab Flow, when we explore the GitLab flow for branching and merging.