Using Git with Dropbox
Posted on March 15, 2012 by Sol

Sometimes you want to keep a git repository private, at least temporary, without owning a server or a paid GitHub account. If you have a free Dropbox account you can host your private repo there.

Open a Terminal window if you are on Linux or Mac, on Windows just start a Bash window from your Git installation. Your Dropbox folder is created by default on HOME for Linux and Mac, or on MyDocuments in Windows.

Navigate to your Dropbox folder:

1
2
cd ~
cd Dropbox

Once you are in ~/Dropbox you will want to create a bare git repo:

1
2
3
mkdir repo01
cd repo01
git --bare init

Now, you can use this folder as a private repository. Let’s try some tests:

1
2
3
4
5
6
cd ~
mkdir local_repo01
cd local_repo01
git init
touch t1.txt t2.txt p.cpp
echo "add some text" > t1.txt

Commit changes:

1
2
git add t1.txt t2.txt p.cpp
git commit -m 'test'

Add the “remote” repo (the one from Dropbox) as origin:

1
git remote add origin ~/Dropbox/repo01

Now, we can push the above files from the master branch to the remote origin:

1
git push origin master

If you want to simulate the workflow on a different machine clone repo01 change some files and save the changes:

1
2
3
4
5
6
cd ~
git clone ~/Dropbox/repo01 test_clone
cd test_clone
ls > t2.txt
git commit t2.txt -m 'some changes'
git push origin master

You can go back to your original working folder and see the changes from the last step:

1
2
3
cd ~
cd local_repo01
git pull origin master

If you want to learn more about using Git I would recommend Pro Git by S. Chacon:

blog comments powered by Disqus