A brief introduction to version control and Git
A version control system (sometimes called revision control) is a tool that lets you track the history and attribution of your project files over time (stored in a repository) and helps the developers in the team to work together. Modern version control systems give each developer their own sandbox, preventing their work in progress from conflicting, and all the while providing a mechanism to merge changes and synchronize work. They also allow us to switch between different lines of development, called branches; this mechanism allows the developer to change, for example, from working on introducing a new feature step by step to fixing the bug in an older, released version of the project.
Distributed version control systems (such as Git) give each developer their own copy of the project’s history, which is called a clone of a repository. This is what makes Git fast, because nearly all operations are performed locally. It is also what makes Git flexible because you can set up repositories in many ways. Repositories meant for development also provide a separate working area (or a worktree) with project files for each developer. Git’s branching model enables cheap local branching, allowing the use of branches for context switching by creating sandboxes for different tasks. It also makes it possible to use a very flexible topic branch workflow for collaboration.
The fact that the whole history is accessible allows for a long-term undo, rewinding to the last working version, and so on. Tracking ownership of changes automatically makes it possible to find out who was responsible for any given area of code, and when each change was done. You can compare different revisions, go back to the revision a user is sending a bug report against, and even automatically find out which revision introduced a regression bug (with git bisect
). Tracking changes to the tips of branches with reflog allows for easy undo and recovery.
A unique feature of Git is that it enables explicit access to the staging area for creating commits (new revisions—that is, new versions of a project). This brings additional flexibility to managing your working area and deciding on the shape of a future commit.
All this flexibility and power come at a cost. It is not easy to master using Git, even though it is quite easy to learn its basic use. This book will help you attain this expertise, but let us start with a reminder about the basics of Git.