Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Pragmatic Version Control Using Git

📅 2012-Dec-06 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ book, git, mercurial ⬩ 📚 Archive

Pragmatic Version Control using Git

With open-source version control systems, I started many years ago with CVS, moved to SVN and a few years ago to Mercurial. Transitioning from SVN to Mercurial is easy, because Mercurial is designed to make this particular transition easy and also because it is actually a simple and elegant tool. Git however is a different beast. I made a mistake falling for the tables which show Mercurial commands and their equivalent ones in Git. I had to perform a simple pull and merge on GitHub recently and I discovered that Git is nothing like Mercurial. Since GitHub is all-pervasive now, I decided to learn the basics of Git at least so that I can work with other people who use it.

Of the many books that try to teach Git, I picked Pragmatic Version Control Using Git by Travis Swicegood. Published in 2008, the book is a bit dated, but it promised to be gentle on beginners and offered to teach by using hands-on examples, which I prefer. The book follows the typical style: a few introductory chapters that introduce the very basic commands and later chapters which take a deeper dive into each of the basic operations of a VCS. The Git repositories for all the chapters can be cloned from GitHub and so following along with the examples in the book is very convenient.

Since I use Mercurial regularly, I noted a few fundamental features of Git which are different from Mercurial:

  1. Staging area: Also called the index, this offers the user a buffer to capture one or more changes, before committing them to the repository.

  2. History: In Mercurial, history cannot be changed, it is sacrosanct. In Git, you can do whatever you want with your history. You can go back and edit commits, merge commits together or split an old commit apart into multiple commits.

  3. Branches: Branches can be fused (rebase) and local branches are easy to create (but need to be named). Also there seem to be subtle and important ways in which local and remote branches differ among Git and Mercurial.

Many of these Git features are available in Mercurial through extensions. Since Git offers them built-in, there is an explosion of basic commands and this is why it appears much more complex than Mercurial. Also, since these features are built-in, people use them and this is why working with Git repositories is harder for Mercurial users.

As an introduction, I found that this book fulfils its purpose. Following along the author by working on a simple repository is essential to learning a VCS. Just knowing the features or commands is pretty much useless. This book covers these bases well and I recommend it as a good introductory book for learning Git.


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧