Git – Synchronize repositories through USB memory stick

Hi All,

Recently I faced a new challenge by synchronizing two workspaces through a USB memory stick since I didn’t have any servers to upload my code to and also GitHub was out of discussion. One repository was on a Mac machine and another one on an Ubuntu machine.

The conclusion I reached was that the best way for me was to create my main repository on the memory stick, then clone this one on my two machines and then with push and pull to upload or retrieve my changes.

Let’s establish some notations in order to make the tutorial simple:

1. Memory stick name = STICK

2. Project name = Test

Also please note that the location for the memory stick is media for Ubuntu and Volumes for Mac.

Step 1:

Copy your project on your memory stick. Let’s say the location is STICK/Test.

Step 2:

Make this location a main repository with the following command:

git init

git commit -a -m "Initial commit"

Step 3:

Clone your repository on Machine A(E.g. Ubuntu machine). First insert your memory stick. Second go to your workspace and Create the folder Test. Then with Terminal go into this folder and run the following command:

git clone /media/STICK/Test

After that you can import your project in Eclipse or in which IDE you used when you created the project that you moved on your memory stick.

If you change code on this machine in the future first go inside your project folder and run:

git commit -a -m "Commit comments"

And then push them to your memory stick main repository(also from inside your project folder):

git push /media/STICK/Temp

You can pull changes from you memory stick main repository(also from inside your project folder) using:

git pull /media/STICK/Temp

Step 4:

Insert your memory stick in Machine B(Mac machine) and clone your repository here with following command:

git clone /Volumes/STICK/Temp

You can apply all Step 3 commands here with the mention that for Mac machine you will use /Volumes/STICK instead of /media/STICK.

Hope this helps and I expect you question, suggestions or improvements.

Andrei.