Using Dropbox for Git Repositories
Ever had a small project you wanted to version control in Git, wanted to keep private (whilst being able to share with friends) but couldn't justify using a paid for private repository? It's really quick and simple to utilise Dropbox for this.
The basic steps for doing this are:
- Setup a bare repository in your Dropbox directory
- That's it!
What is a Bare Repository?
A 'bare' repository is a repository that doesn't actually show any of the repositories files. It contains the details of the repository; the stuff that is normally stored in the
.gti directory. It's the type of repositories a lot of remote providers use (GitHub, etc) when you create a new repository through their UI due to the fact is is designed to be a place you push your changes to and pull any changes from but not perform any direct file edits or commits in.
Setting Up Your Repository
First up, you'll want to create a directory to store your repositories in. The name you choose is not important, other than I wouldn't use any spaces.
Next, we create the actual bare repository in the newly created directory
cd ~/Dropbox/VersionControl git init --bare my-repository.git
if you look inside your new
my-repository.git directory you will see it contains the details of your repository
-rw-r--r--@ 1 kirkd staff 23 29 Sep 19:06 HEAD -rw-r--r--@ 1 kirkd staff 111 29 Sep 19:06 config -rw-r--r--@ 1 kirkd staff 73 29 Sep 19:06 description drwxr-xr-x@ 11 kirkd staff 374 29 Sep 19:06 hooks drwxr-xr-x@ 3 kirkd staff 102 29 Sep 19:06 info drwxr-xr-x@ 7 kirkd staff 238 29 Sep 19:08 objects drwxr-xr-x@ 4 kirkd staff 136 29 Sep 19:06 refs
That is all you need to do to setup your repository. Changes will be synced (and backed up) via Dropbox whenever a change is pushed to the repository. As you can also share the directory (which is your repository) with friends/colleagues it will syncronise changes whenever they push them too.
Using your Repository
Having a bare repository configured is all well and good, but we need to be able to push changes to and pull changes from it before it's of any use to us. Thankfully, that's even easier.
Create a new directory for your work
cd ~/Projects mkdir my-new-project
Initialize a new git repository in your project directory
cd ~/Projects/my-new-project git init touch README.md git add README.md git commit -m "Initial commit"
Last step is to add the bare repository as a remote and push our changes
git remote add origin ~/Dropbox/VersionControl/my-repository.git git push -u origin master
You will notice Dropbox syncing the changes that you just pushed. Cloning the repo is just as simple
cd ~/Projects git clone ~/Dropbox/VersionControl/my-repository.git another-copy-of-my-repository
You may get an error along the lines of:
error: unable to find ba2ad105b3955b3f73d79072bc52ee4326cd2e4f error: refs/heads/master does not point to a valid object! Your configuration specifies to merge with the ref 'master' from the remote, but no such ref was fetched.
This can be caused if you are trying to pull changes which haven't finished syncronising. Wait for the syncronisation to finish and try again. For this reason, this solution isn't suitable if a large number of people need to access the repository.