Git on USB Stick


Sometimes within your development team, you might want to create a new or port an existing local Git repository to a USB drive/stick and share it. In such cases, what you need is to create a bare repository so that all developers can collaborate and push their changes to it.

Due to the distributed nature of the Git version control system, contents cannot be directly edited in the bare repository. The following more or less demonstrates the structure of a bare sharing repository (called sharing repository).

1
2
3
4
5
6
7
8
9
10
drwx------ 7 4,0K Apr 23 14:11 ./
drwx------ 3 4,0K Apr 23 14:11 ../
drwx------ 2 4,0K Apr 23 14:11 branches/
drwx------ 2 4,0K Apr 23 14:11 hooks/
drwx------ 2 4,0K Apr 23 14:11 info/
drwx------ 4 4,0K Apr 23 14:11 objects/
drwx------ 4 4,0K Apr 23 14:11 refs/
-rw-r--r-- 1 104 Apr 23 14:11 config
-rw-r--r-- 1 73 Apr 23 14:11 description
-rw-r--r-- 1 23 Apr 23 14:11 HEAD

Instead, users need to clone the bare sharing repository to create a local one (called working repository) with the following familiar structure.

1
2
3
drwxrwxr-x 3 4,0K Apr 23 14:11 ./
drwxrwxr-x 11 4,0K Apr 23 14:11 ../
drwxrwxr-x 7 4,0K Apr 23 14:11 .git/

Having their own copies of the repository, users can now modify contents locally and push changes back to the sharing repository to make changes available to others.

Creating a New Bare Sharing Repository

Creating a new bare repository on your USB drive is as easy as follows:

1
2
3
4
cd /path/to/usb/stick
mkdir <repo-name>.git
cd <repo-name>.git
git init --bare

Porting an Existing Working Repository

In case you want to create a bare sharing repository based on an existing working one, take the following steps:

1
2
3
4
5
6
7
cd /path/to/usb/stick
mkdir <repo-name>.git
cd /path/to/local/working/repository
# create the bare repository by cloning the current one
git clone --bare --no-hardlinks . /path/to/usb/stick/<repo-name>.git
# enable pushing to an alias instead of typing the whole URL
git remote add usbstick file:///path/to/usb/stick/<repo-name>.git

Notice that according to Git documentations “–no-hardlinks” forces the cloning process from a repository on a local filesystem to copy the files under the .git/objects directory instead of using hardlinks.

Testing Your Bare Repository

At this point developers can create their working repository by cloning the bare repository on the USB drive.

1
git clone /path/to/usb/stick/<repo-name>.git /path/to/destination
Share Comments