Software Woes

Rants, tips and tricks



Saturday, February 21, 2009



Setting up Git offline work via USB memory stick

I have a home laptop and an office desktop computer. When I leave office, everything is shut down, so there is no way to access the git repository online. Since I didn't want to drag my notebook to work everyday, I got the idea to have a git repository on my USB memory stick.

One of the requirements was that it is a bare repository so it does not take too much space. I had a lot of trouble figuring out this one, and finally I got the right way when I understood how git is meant to be used.

I created a big file on my FAT filesystem, and formatted in in ext2 with something like:

dd if=/dev/null of=/mnt/stick/repos.ext2 bs=1024 count=500000
mkfs.ext2 /mnt/stick/repos.ext2

Then I mounted it and created a bare copy of my repos:

mount -o loop /mnt/stick/repos /mnt/repos
cd /mnt/repos
git clone /home/milanb/repos repos

When I go home, I repeat the mount on my laptop and pull the changes into local development repository:

mount -o loop /mnt/stick/repos /mnt/repos
cd ~/devel/repos
git pull /mnt/repos/repos master

After I commit the changes, just push it back to stick:

git push /mnt/repos/repos

Now, the tricky part, when I go back to the office, I was (stupid) to try to push the changes from the stick to local repository. There are ways to make this work, but quite awkward and error prone. Git is not meant to be used that way. The rules are simple, if you do everything right:

- you should never need to pull/fetch into bare repos
- you should never need to push into non-bare repos

So, what I really needed to do is just to reverse the logic and pull changes from stick into my local repository:

git pull /mnt/repos/repos master

It merges (unless there's confict) and everything is fine. To prevent from typing all those long paths, you can define aliases (remotes) via git-remote command:

git remote add /mnt/repos/repos stick

And later just do these to pull and push:

git pull stick master
git push stick

All that time I used SVN and CVS just got that centralized way of thinking into me. Finally I'm free ;)

All I can say is: Git simply rocks!

4 Comments:

At 9:58 AM, Anonymous Graeme Geldenhuys said...

Your 'git remote add' command is incorrect.

It should read as follows:

git remote add stick /mnt/repos/repos

The name of the remote repository before the URL of the repository.

 
At 8:17 AM, Blogger dov said...

Why exactly did you create the ext2 loopback filesystem on your usb stick? I'm using a bare git repo straight under the fat32 file system, and so far I haven't seen any problems. I actually found your blog posting after having looked for whether bare git repos are supported under fat32.

 
At 1:36 AM, Blogger Milan Babuskov said...

I don't recall the original reason, but I still do it like that currently because I can always give my USB stick to someone with Windows machine to transfer some files and I know my repository won't be seen nor attacked by some virus.

 
At 3:18 AM, Blogger Toolman said...

I think you want to make a bare clone, so your command should be:

git clone --bare src dest

 

Post a Comment

Links to this post:

Create a Link

<< Home