Whenever a student or colleague asks me about getting started with git, I look up a set of resources I found quite enlightening and / or useful and give them a bunch of links, often with a hand-crafted description of each. To repeat myself less often in the future, I’m now using the power of a blog post that consolidates that material.
This is that blog post.
People asking me about git know that it’s a source control system and that it is, well, a little different. It’s distributed, you can use it locally without a network connection to a central server, and it’s incredibly hip. So I’ll skip that part. Let’s assume you’ve installed git and only know Subversion or something similar and you don’t know where to start. You need a mental model of git.
The Git Parable
This is a story which puts you in the place of someone inventing a git-like system. The author walks you through the problems of version control and how to solve them with some basic tools — like directories, index files, and hashes. This made me feel like I understood git for the first time — to a certain extent, of course.
Once you know the basics of “the git model”, you should get your hands dirty. From the website: “Git Immersion is a guided tour that walks through the fundamentals of Git, inspired by the premise that to know a thing is to do it.”
Git’s commands and what they affect
Now that you’ve used git and its different commands, it’s helpful to have an overview that helps you putting everything together and that you can come back to for later reference. This interactive cheat sheet will show you which git commands will affect which areas of a git repository.
Git’s commands and what they affect
Git & SVN
While changing to git improves your life in several ways, you might need to support legacy Subversion repositories. Git integrates with SVN using the “git svn” command. I use it to push my commits to the Subversion server at work, so students that don’t use git (yet) may still access the most recent version of a project.
This blog post explains how to setup git with SVN when starting with a git repository. This other blog post discusses and solves some of the caveats that might occur with this setup.
In addition to Subversion, I push the commits to a git server I host myself — this allows students that do use git to avoid using Subversion. I found the following order of commands to be essential for making this setup work:
git commit // commit to local git repository
git svn fetch && git svn rebase // fetch updates from the SVN server
git svn dcommit // commit to Subversion server
git push origin master // commit to hosted git server
git svn dcommit will rebase or reset your repository. Even though that might sound dangerous, it isn’t — it simply means that your local repository is updated to reflect the current state of the SVN repository. But it also means that if you first push to origin and then dcommit to SVN, your local repository will have changed after the latest push to origin.
git status will show that your local repository and origin have diverged. This is not what I want, so I strictly adhere to the above order.
It’s very probable that you’ll want to put your repositories somewhere place, either as a backup, to share them with someone else, or for collaboration. I like the highly popular GitHub — they offer public repositories for free and private repositories for a modest monthly fee. Additionally, they have some other great features, such as easy forking of projects you like, easy sending and merging of pull requests, a bug tracking system, a wiki, and hosting of static web pages. As an alternative that also supports SVN, you might try codebase.
Hosting git yourself using gitolite
If you have a server and want to use it to host your git repositories yourself, gitolite is the best answer I’ve found so far. It’s easy to install and maintain — actually, you use git itself to update its configuration. Here are the installation instructions.
A List of Cheat Sheets and Useful Aliases
This page holds a plethora of cheat sheets and other useful little tricks for your daily work with git.
Pro Git: Professional Version Control
If you have any further questions regarding git, you might want to take a look at Pro Git — it’s a full book exclusively about your favorite subject, and you may read it for free, too! Of course, if you like the book and use it regularly, it might be practical to buy it. Also, it would be a nice thing to do.
And that’s it for my little round-up of git resources! If you feel I’ve missed anything essential or you find an error, just drop me a line on Twitter here.