Saturday, January 5, 2013

Version Control, Happy New Year!

Happy 2013! I Hope all your celebrations were joyful and safe. I played board games and had too much food at my house, and all was well. My resolution this year: Maintain this blog. 52 posts by December 31. Since I'm already behind schedule from my first "weekly blog post," let's get started!

My foray into Version Control

I worked on a fairly involved class project with a partner, and we used... Google Docs, e-mail, Dropbox, keeping multiple text files of things, "are you working on this now? I'm going to change it on the server," and "commenting out code I think might be useful later if this doesn't work out." Needless to say, this resulted in a few dozen "why aren't we using version control, again?" as we went along. Hence, my foray!


Basics

I... had the beginnings of a quick overview of version control, but I got tired of re-stating what others have already said. So, here is Version Control by Example, by Eric Sink. It 's a great overview of Version Control Systems (VCSs), starting with "well, what are these things, and what are the differences between them all?" and ending with "now that you know the basics, here are some in-depth details and best practices to mull over." It goes over (with examples) the basics of the different systems (distributed vs. centralized), and then uses one fairly entertaining example to show the different commands and workflows for SVN, Git, and Mercurial (I skipped the parts on Veracity).


Git and Mercurial (and Bazaar)

The couple places I've worked that did development used Subversion. But apparently Distributed Version Control is The Way of the Future, so I decided to look into it. The three big players in DVCS right now are Git, Mercurial, and Bazaar.

When I tried Git a few months ago, I wasn't at all familiar with the command line, and was using Windows. So I tried Git for Windows, or maybe msysGit, I'm not sure. And I didn't understand it, or I broke it somehow - Git does not get very much support on Windows (though I'm sure you could get it to work if you poked at it a bit). 

This week tried out Mercurial, the "other" DVCS. The difference was, it works for Windows out of the box (just type in hg into the Windows command line), and I had a bit more of an understanding of the command line and version control in general. I installed TortoiseHG, an extension of Mercurial that provides file-right-click options and a GUI. I think people tend to like the Tortoises (TortoiseSVN, TortoiseGit) for those reasons. However, I found the command line options for Mercurial to be far more intuitive than playing with the Hg Workbench.

The differences between Hg and Git are outlined on Atlassian's Guide to DVCS. I think they're pretty much the same (for a novice user such as I, who will only be using it for small projects with a few others at most). For me, Git requires me to use Git Bash (since it doesn't work on the Windows command line), and the advantages it claims either don't apply to me or are beyond my understanding. So while I have both systems available on my computer, I will be using Hg for my own projects.

Atlassian's guide also mentioned Bazaar, which seems like another great option for a DVCS. Still, when talking about DVCS, Git seems like "the thing," with Mercurial being "the other thing" and Bazaar being "oh yeah some people use that one too." I didn't try out Bazaar.


Bitbucket and Github

So now that I picked out a source control management tool, it was time to choose where to host my code! (In reality, these two choices happened at the same time and can go hand-in-hand). The go-to place is Github; it's got a huge community, and some would say that if open-source code isn't on Github, then it doesn't exist. As the name implies, code hosted on Github is managed by Git (although you could get the hg-git plugin if you wanted to host your Hg-managed code on Github, something I haven't tried myself).

The "other code-hosting place" is Bitbucket. In addition to supporting both Git and Mercurial, it also allows you to have free private repositories (you have to pay for these on Github) and has a pretty decent tutorial, to boot. I'll admit, I got bored with the tutorial by the time I got to the part about SSH, so I haven't set that up yet. Still, I think it's pretty comprehensive, and friendly to new users. Bitbucket even has the capacity to publish a static website, something I'd been thinking about using as a to-do list (I'm not so keen on this particular idea anymore, but the hosted website is still a neat feature).


Ending thoughts

I spent a lot of time reading about source control and the different systems. In the end, the choice between the systems didn't make much of a difference to me (I envision myself getting better with Git and Github when I find some open-source projects to work on). The reading was informative, and it gave me a much better idea of what happens when I type hg commit. However, I also spent a lot of time trying to familiarize myself with all the different features of Hg and Bitbucket (and, to a lesser extent, Git), with little success. After a cursory overview of the workflow and different commands, I think the best way to learn the tools is by simply using them. I'll probably be reading the Mercurial guide as I do more things with it, but on an as-needed basis rather than all at once.

All that being said... Check out duck.py on Bitbucket! It's got a few new commits to it, and has even been forked!

Next update: cygwin! 

2 comments:

  1. I shall be the proverbial non-coder... ummm I'm so lost here. I get the idea of file sharing/collaboration, but what is version control exactly?
    I expect a very obvious answer to this - and also feel very stupid after hearing it :P

    ReplyDelete
  2. Yeah, most of the details here are specific to different systems of version control, so not too interesting unless you actually want to use it. I'm glad you got through the post, though =)

    Version control is, quite simply, a system to keep track of every "version" of a thing that you've written. It's quite useful for code, because we tend to delete chunks of it thinking we won't need it, and then decide yeah, we really do need it. Or write more of it, only to realize that the stuff we wrote completely broke what we had before, and which lines did we change again?

    You can use these same systems to keep track of other stuff too, like having a repository (and all the previous drafts) of all the blog posts you've ever written, for example. It works best with things that are text-only, but I suppose it could be useful for working on a document with someone (google docs has a revision history button, but I find it not as easy to look at as the github version).

    So yeah. If you ever for some reason find yourself curious about version control, the first guide I posted (Version Control by Example, by Eric Sink) is really clear and entertaining.

    ReplyDelete