A Brief History of Revision Control
Well talk more about the core philosophy behind Git in a moment, butfirst, lets step through the evolution of version control systems ingeneral.
Files and Folders
Before the advent of revision control software, there were only files andfolders. The only way to track revisions of a project was to copy the entireproject and give it a new name. Just think about how many times youvesaved a backup called my-term-paper-2.doc
. This isthe simplest form of version control.
Revision control with files and foldersBut, its easy to see how copying files from folder to folder couldprove disastrous for software developers. What happens if you mis-label afolder? Or if you overwrite the wrong file? How would you even know that youlost an important piece of code? It didnt take long for softwaredevelopers to realize they needed something more reliable.
Local VCS
So, developers began writing utility programs dedicated to managing filerevisions. Instead of keeping old versions as independent files, these new VCSsstored them in a database. When you needed to look at an old version, you usedthe VCS instead of accessing the file directly. That way, you would only have asingle checked out copy of the project at any given time,eliminating the possibility of mixing up or losing revisions.
Local version controlAt this point, versioning only took place on the developerslocal computerthere was no way to efficiently share codeamongst several programmers.
Centralized VCS
Enter the centralized version control system (CVCS). Instead of storingproject history on the developers hard disk, these new CVCS programsstored everything on a server. Developers checked out files and saved them backinto the project over a network. This setup let several programmers collaborateon a project by giving them a single point of entry.
Centralized version controlWhile a big improvement on local VCS, centralized systems presented a newset of problems: how do multiple users work on the same files at the same time?Just imagine a scenario where two people fix the same bug and try to committheir updates to the central server. Whose changes should be accepted?
CVCSs addressed this issue by preventing users from overriding otherswork. If two changes conflicted, someone had to manually go in and merge thedifferences. This solution worked for projects with relatively few updates(which meant relatively few conflicts), but proved cumbersome for projects withdozens of active contributors submitting several updates everyday: developmentcouldnt continue until all merge conflicts were resolved and madeavailable to the entire development team.
Distributed VCS
The next generation of revision control programs shifted away from the ideaof a single centralized repository, opting instead to give every developertheir own local copy of the entire project. The resultingdistributed network of repositories let each developer work inisolation, much like a local VCSbut now the conflict resolution problemof CVCS had a much more elegant solution.
Distributed version controlSince there was no longer a central repository, everyone could develop attheir own pace, store the updates locally, and put off merging conflicts untiltheir convenience. In addition, distributed version control systems (DVCS)focused on efficient management for separate branches of development, whichmade it much easier to share code, merge conflicts, and experiment with newideas.
The local nature of DVCSs also made development much faster, since you nolonger had to perform actions over a network. And, since each user had acomplete copy of the project, the risk of a server crash, a corruptedrepository, or any other type of data loss was much lower than that of theirCVCS predecessors.
The Birth of Git
And so, we arrive at Git, a distributed version control system created tomanage the Linux kernel. In 2005, the Linux community lost their free licenseto the BitKeeper software, a commercial DVCS that they had been using since2002. In response, Linus Torvalds advocated the development of a newopen-source DVCS as a replacement. This was the birth of Git.
As a source code manager for the entire Linux kernel, Git had several uniqueconstraints, including:
- Reliability
- Efficient management of large projects
- Support for distributed development
- Support for non-linear development
While other DVCSs did exist at the time (e.g., GNUs Arch or DavidRoundys Darcs), none of them could satisfy this combination of features.Driven by these goals, Git has been under active development for several yearsand now enjoys a great deal of stability, popularity, and communityinvolvement.
Git originated as a command-line program, but a variety of visual interfaceshave been released over the years. Graphical tools mask some of the complexitybehind Git and often make it easier to visualize the state of a repository, butthey still require a solid foundation in distributed version control. With thisin mind, well be sticking to the command-line interface, which is stillthe most common way to interact with Git.
Installation
The upcoming modules will explore Gits features by applying commandsto real-world scenarios. But first, youll need a working Gitinstallation to experiment with. Downloads for all supported platforms areavailable via the official Git website.
For Windows users, this will install a special command shell called GitBash. You should be using this shell instead of the native command promptto run Git commands. OS X and Linux users can access Git from a normalshell. To test your installation, open a new command prompt and run git--version
. It should output something like git version 1.7.10.2(Apple Git-33)
.
Get Ready!
Remember that Rys Git Tutorial is designed todemonstrate Gits feature set, not just give you a superficialoverview of the most common commands. To get the most out of this tutorial,its important to actually execute the commands youre readingabout. So, make sure youre sitting in front of a computer, andlets get to it!
The Basics
Now that you have a basic understanding of version control systems ingeneral, we can start experimenting with Git. Using Git as a VCS is a lot likeworking with a normal software project. Youre still writing code infiles and storing those files in folders, only now you have access to aplethora of Git commands to manipulate those files.
For example, if you want to revert to a previous version of your project,all you have to do is run a simple Git command. This command will dive intoGits internal database, figure out what your project looked like at thedesired state, and update all the existing files in your project folder (alsoknown as the