Portable Git Repository

Do you ever need a source repository in your flash memory which you can take everywhere you go?

I can hear, "why should i need such a weird thing?" I don't know pal... What can i say about your weird motivations? I'm just here to answer, though. :)

Well, joking aside, you may be working on multiple computers, or you may have connectivity issues, or both. Or simply you don't want your code on some remote location, whatever...

For whatever reason, if you want it, you'll need to decide where to put it on, and take the following steps.

You may use any folder on your computer, or a network mount. But for being portable, it is best to choose some flash memory or USB drive.

After that, you need to create git repository on this device.

$ git init --bare /path/to/repository/my-portable-repo.git

You should add --shared option, if you want other users to push changes into your repository.

$ git init --bare --shared=group /path/to/repository/our-portable-repo.git

You may need to fiddle with --shared values to tune it for your preferences, refer to git manual pages for it.

After your repository was initialized, let's continue with our first clone command.

Let's assume our repository path is /media/bilbo/FlashMemory/hello-gandalf.git.

Switch to your working directory and invoke following command.

$ git clone /media/bilbo/FlashMemory/hello-gandalf.git
Cloning into 'hello-gandalf'...
warning: You appear to have cloned an empty repository.
done.

Change into your cloned repository folder and create something to commit; say hello to Gandalf!

$ cd hello-gandalf
$ echo "echo Hello Gandalf!" > hello.sh
$ sh hello.sh
Hello Gandalf!

Now you have something to commit... Add your file to git :

$ git add hello.sh

Invoke commit command :

$ git commit -m "Hello..."
[master (root-commit) e35603b] Hello...
 1 file changed, 1 insertion(+)
 create mode 100644 hello.sh

Push changes to your local repository :

$ git push origin master 
Counting objects: 3, done.
Writing objects: 100% (3/3), 233 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /media/bilbo/FlashMemory/hello-gandalf.git
 * [new branch]      master -> master

After this, you can follow regular git flow...

Enjoy your new portable git repository!