Thursday, 1 March 2012

Friendly Git

I thought I’d start the blog off with a post about my current version-control-system-du-jour - Git. First off I’m using Windows. This means that dealing with the unfriendly command line tools is only a very occasional annoyance. Don’t get me wrong I'm sure the command line is super fast if you use it every day but when I first started using Git every single time I wanted to do anything would require several trips to the man pages.

I was a huge fan of TortoiseSVN and was over the moon when TortoiseGit was released. So if you want to get started and you’re using Windows then hop on over to http://code.google.com/p/tortoisegit/ and get installing (actually one minor annoyance - before you do that you need to install msysGit http://code.google.com/p/msysgit/downloads/list).

Ok now using Git on one machine is cool and all, and if you are happy to have your repository public then there are plenty of free hosting sites. However none of them fitted my criteria of free, private and fast with an unlimited number of repositories.

Enter Dropbox. You probably know of the cloud storage solution (in fact there are others - SpiderOak looks particuarly interesting) and it is indeed very cool. But when you combine it with Git... way cooler than the sum of the parts. I use it mainly to share my project across multiple computers but you can also share the repository folder with other people.

Git with DropBox

  1. Create a new repository on your local drive (for example AwesomeProject27). Make sure you add at least one file and commit it.
  2. Create a folder in your Dropbox with the same name but extension .git (e.g. AwesomeProject27.git). This is simply following git convention.
  3. Inside that folder right click and create a repository and be sure to click the checkbox ‘Make It Bare (no working directories)’
  4. Go back to the repo on your local drive and right-click and choose Git Sync from the TortoiseGit context menu
  5. You need to setup a new Remote URL so click the Manage button
  6. In the Remote field add ‘origin’ (or some other name you like for the remote depo). In the URL add the full path to the folder you created in step 2 and you’re done, click OK.
  7. Select ‘origin’ in the Remote URL field and now click the Push button at the bottom. This will push your current committed changes to the DropBox folder.
Now you have done this setup you can easily make changes on your local machine, commit them and Push them to the DropBox. So how about working from a different computer? Couldn’t be simpler. Assuming you have TortoiseGit simply right-click the folder you want to hold the repo and choose Git Clone. In the URL field enter the path to AwesomeProject27.git and hit OK. This will pull the whole thing down to the new folder.

Working without Git

You may be collaborating with some people who do not give a damn about version control systems. These guys may be awesome at what they do so hey I’m not going to complain! The best way I found to handle this is create a branch for them. Then when they want a drop of the game update their branch with a working build and send then a copy of the app. You switch back to your branch and carry on working. If they have some new stuff for you switch to their branch, copy their data onto the folder (check it still works of course!) and then commit it. You can then merge their changes into your branch. Make sure you Push their branch to the DropBox just in case your machine dies.

Most of these should be easy but I learned a little trick to export a clean copy of a branch which works from the Git command line. If you allowed msysGit to install its Explorer plugin then you should be able to click your repo and choose Git Bash. If not, run Git Bash from the Start menu and navigate to the repo. Say your branch is called 'simon' use this command.

git archive simon -o ..\AwesomeProject_Simon_20120123.zip
This will create a zip file of the current state of the current branch without any .git meta data. Archive creates an archive (duh) but if you actually want it in the unpacked form you can pipe the output into tar directly.
git archive simon | tar -xC ..\OutDirThatExists

No comments:

Post a comment