Getting started with Git

Subversion has been my VCS of choice the last few years. We use it at work, and so using it at home too made me that much more comfortable with it and knowledgeable about it. If you want to try it out, check out VisualSVN. It’s small, free, and only takes a few minutes to set up. I had it running on a spare machine with some other development tools.

I read and hear more about Git than SVN nowadays (perhaps due to the popularity of sites like GitHub and Bitbucket). The fundamental difference between the two is that SVN is centralized while Git is not.

In SVN, the main repository and the full history of your team’s files is on a single server somewhere. You “check out” or “pull” a branch, getting you only a single version of the files (not the full history). If the main repository corrupts or the server crashes, and you don’t have backups, you’re SOL. And if you’re not connected to the central repository, you cannot check in your code during development, or roll back to any previous version other than what you checked out.

Git, on the other hand, is a DVCS – the D is for decentralized. Every developer has a full copy (“clone”) of the repository on their machines. Without any connection to the Internet, you can view all historical versions and check in new changes. There is no single point of failure anymore – if one copy is lost due to a hard disk failure, everyone else on the team has a fully copy too. And size isn’t horrible if you’re not checking in executables and movie files into your repo – text files compress well and only changes between versions are stored in the repo.

Hosted vs Local

With a centralized repository like Subversion, you need to consider where the repository will be.. well… centralized. This isn’t a consideration with a DVCS like Git.

  • You can create a Git repo on your local machine, then sign up for a hosted service and upload it there. A complete copy of your repo is in both places.
  • You can sign up for an online service, create a repo via their interface, then install Git locally and clone the repo onto your machine. A complete copy is in both places.

The hosted service is just one more place where your repository is cloned.

Ok I lied. Sorta. The hosted service is probably the only publicly accessible clone of your repo that others can pull from. They cannot pull from the clone located on your home pc, unless you’ve done some advanced configuration involving your ISP (or a dynamic DNS service), router and firewall. In that sense, the hosted service is sorta acting like a central repository. But you can have several “central” repositories, or zip up your local clone and send it to a friend to use without their having to clone it from the hosted service. For a company, the term “central” becomes a convention, with everyone agreeing that the clone in a particular place is the central repository.

Web-based Git Hosts

Before anything else, download and install Git. Someone at Atlassian wrote up a helpful tutorial in the Bitbucket documentation for setting up Git on Windows, so I won’t rehash it here. It was easy – I accepted all the defaults.

There are some reliable Git hosts out there offering their services for free – two well known ones are GitHub and Bitbucket. In the end, I signed up for both and would use one or the other depending on my needs.

GitHub provides unlimited public repositories with unlimited users, but if you want to keep anything private you’ll pay at least $7/mo. If I had an open source project or wanted to share something with the world, I’d use GitHub.

Github pricing

Bitbucket, on the other hand, provides unlimited private (and public) repositories, but only for a few users. Teams will pay at least $10/mo depending on size. When I’ve got something I’m playing around with or trying out, that I want backed up and accessible from multiple locations but am not ready to share, I’ll use Bitbucket.

Bitbucket pricing

Setting up the Git environment

The same helpful individual at Atlassian wrote up a tutorial for creating an account and your first Git repo as well. I created my first private repo at Bitbucket named “Sandbox”… just a misc place to dump things I’m trying out. There’s 3 quick ways on the main screen to create a repo.

Bitbucket creating a repo

Now I want to clone the repo to my machine. This can be achieved using the tools that install with Git, found in the Start menu. Here’s a tutorial on cloning your Git repo and adding source files.

git start menu shortcuts

I imagine some things need to be done with the command line tool, but personally I prefer a friendly GUI to this:

gitbash

There’s also the built-in GitGui. Personally I prefer a friendlier  GUI to this. It’s a few links to basic command line commands. It should be called GitFastLinks… or GitShortcuts.

gitgui

There are quite a few advanced GUI clients to choose from too.

  • If you decide to use GitHub primarily, you may want to try GitHub Windows by GitHub.
  • If you decide to use Bitbucket primarily, you may want to try SourceTree by Atlassian (creators of Bitbucket).

I chose SourceTree, since I’m a fan of Atlassian products (I use Confluence at home too). The setup was pretty straight-forward; I accepted all the defaults. I recommend installing Git first, since SourceTree will detect and automatically enable it. You’ll also have a chance to enter your Bitbucket and GitHub account information, so you might as well sign up for those first. If you aren’t ready for some of this while you’re going through the setup process, you can always restart it later via the File menu.

sourcetree setup wizard link

Well, now I’ve got my first Git repo and a local clone. Off to commit something to it. Happy coding…

Subscribe to Weekly Updates!

Get an email with the latest posts, once per week...
* indicates required