Getting to Grips with Git

John Dyer, Former Viget

Article Category: #Code

Posted on

Since this is my first article for Viget Extend, I’ve decided to start with a short introduction. My name is John Dyer and I joined Viget at their Durham, NC, office as a development intern in July. Since then I’ve been working full time on SpeakerRate, an in-house Pointless Corp project. Although I was relatively familiar with Rails and had been using it on and off for a couple of years, this was my first time working on a large project. Needless to say, I’ve learned a lot.

Any project that has multiple developers, designers and others working on it at any given time needs some system of version control so that changes don’t quickly turn into a pile of meaningless nothing, causing confusion and conflicts within the application and amongst the developers themselves. When it comes to Ruby on Rails projects, Git seems to be the VCS (version control system) of choice. Like many other tools commonly used in the Ruby community, Git was familiar to me, but I hadn’t had much practice with it. Using Git on a daily basis over the last couple of months, I have amassed a collection of techniques, tips, and tools that have made version control with Git a breeze.

Getting Started

  • Git for the Lazy This is a very short and informative article that takes the reader step-by-step through the basics of Git. It teaches you how to make commits, manage and merge branches, check logs and diffs, and fix basic mistakes. This was great when I was just beginning my work here and most of the tasks assigned to me were pretty simple. However, as the tasks became increasingly complex and my understanding of Git started to grow, I quickly outgrew this reference. I wanted to know more about managing my growing number of branches, specifically merging and rebasing.

  • Peepcode Git Screencast Another good introduction to Git that will actually teach you quite a bit more than Git for the Lazy. This screencast (like most of Peepcode’s releases) is worth more than the $9 they charge for it.

  • Pro Git Book Not necessarily beginner-specific, this is a full-length book on using Git that can be purchased in hard copy or read for free online.

  • GitReady “Learn Git one command at a time.” Once you have the basics down, GitReady will feed your knowledge-hungry brain with articles pertaining to specific Git topics, commands, and workflows.

GUIs

  • GitX A Visual Git tool that helps with understanding how Git actually manages your repository. This program allows you to easily see your commit history across all branches as well as make commits, view diffs, and manage branches

    Pro Tip: GitX is a great tool, but unfortunately it hasn’t had an official release in quite a long time. That hasn’t stopped the open source community from continuing development on their own, and some of the experimental builds online have tons of useful features not currently included in the official release. Take a peek around GitHub and see what’s out there. I use brotherbard’s build.

  • Tig Tig is a similar tool to GitX and offers all the same features, along with a myriad of more advanced ones. The biggest difference between these two tools is that while GitX is a native Mac OS X application, Tig runs entirely inside your terminal. I use it all the time, and it is great for manually staging files, making commits, comparing branches and files, and much, much more. I strongly suggest checking it out once you feel comfortable using Git and GitX.

  • Gitbox A newcomer to the Git GUI selection, this tool offers similar features to GitX but in a much more streamlined interface. This software is also under active development. It seems that it will eventually have a price tag attached to it, though. I just discovered this a few days ago, so I haven’t had much time to play with it yet, but the interface is absolutely beautiful.

  • Gity This is yet another Git GUI application that I was recently informed of by Viget developer Brian Landau. Like Gitbox, it offers a beautiful interface and a very streamlined workflow. Unlike the other Git GUIs, Gity offers many advanced Git features as well. This application gives experienced Git users a nice alternative to the Git command line interface.

Useful Commands

  • git add —patch Useful for staging changes you’ve made to files. It allows you to pick and choose which changes you want to include in your next commit.

  • git rebase —interactive Very powerful command, but also has the potential to be dangerous. This command allows you to edit the commits which are being rebased. To put it simply, you can use this during a rebase to reorder your commits, remove unwanted patches, and make edits along the way. I recommend reading this article to get a better understanding of its use if the Git docs just aren’t doing it for you.

  • git stash Allows you to move changes from your working copy into a holding area which you can then apply at a later point in time. (Note: You can have more than one stash of changes stored.) Use git stash list to view your current stash contents.

Additional Resources & Tips

  • Peepcode Git Internals PDF It’s a great read and you will definitely end up with a solid grasp on Git’s inner workings. That is, if you can understand the concepts being presented. I suggest holding off on this until you’ve come to trust Git to do what you expect when you enter a command and have read through some of the more advanced topics on GitReady. Another read that covers similar topics, but is a bit more lightweight, is “The Workflow” section of the Git manual.

  • Create aliases for Git commands you use often. Aliases let you execute commands using shortcuts you define. To get an idea of what is possible with aliases, take a look on Github and browse users’ dotfiles (mine are available here).

  • Prevent a messy commit history. Check out this article titled “Only You Can Prevent Git Merge Commits,” by one of my coworkers, Clinton Nixon.

I hope you've found these resources useful and learned something new. An article like this would have helped me immensely during the early stages of my internship, so I thought I’d get it all down. If you have any other Git resources or feel like sharing your "Git Workflow", please leave a comment below. Also, if you have any questions about these links or have a resource that you think absolutely belongs on this list, shoot me a message on twitter.

Related Articles