Git With Dropbox

These are my notes on setting up Git with Dropbox. I’m going to cover my view of a flexible Git-based workflow should be. Currently, my workflow includes tools like Subversion, Redmine, Trac and Hudson. So, my goal is to be able to migrate seamlessly and reach a sustainable state using git at the end of the day. Let’s set my requirements for the final solution:

  • Subversion interoperability
  • Share code/data with colleagues, using Git or Subversion
  • Track private branches and share private branches between my computers
  • Merge data between private and public branches

Global Git configuration

There is some configuration that applies to all repositories. First, personal information:

git config --global "George Goulas"
git config --global

Also, I like to see colors:

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto

All the above commands modify the file ~/.gitconfig.

Setting up repositories

Setting Git in Dropbox

I need a directory in Dropbox to consider as my private repository, central for my computer systems. I can create it using the following commands:

mkdir -p ~/Dropbox/git/repos/Project.git
cd !$
git --bare init

The special command is the last one, where I define a bare Git repository. Normal Git repositories contain the tracked project files and the repository information is in .git directory. Bare repositories have only the contents of the .git directory.

A blog post suggested also the following, but as I have seen, it is set after the last previous line, so it is not needed:

git config --bool core.bare true

To check, see the result of:

git config core.bare

Setting a normal Git Repository

Let’s assume that we are going to create a Git repository in ~/work/Project.git, which is going to push code to the Dropbox repository we just created. We assume that the directory ~/work/Project.git already has code in it, but this is not actually required.

cd ~/work/Project.git
git add .
git commit -am "Initial commit"

Now we want to create a remote repository, named dropbox, to point to our Dropbox repository.

git remote add dropbox file://$HOME/Dropbox/git/repos/Project.git

We can configure to use dropbox remote by default, with the following commands:

git config branch.master.remote dropbox
git config branch.master.merge dropbox

We can see what remote repositories we track in this repository and the tags they have, with:

git remote -v

To push our code to dropbox, the command is:

git push

To pull code from dropbox, the command is:

git pull -p

I a branch drom dropbox has been deleted, the above command will not synchronize the local repository. In order to do that, the prune (-p) option is needed.

git pull

Clone to create a Git repository

Suppose we just want to start work on a new computer. In this case, we need to clone the repository. This is going to work like this:

cd ~/work
git clone -o dropbox file://$HOME/Dropbox/git/repos/Project.git

The defaults for push and pull are still needed:

git config branch.master.remote dropbox
git config branch.master.merge dropbox

Git Workflow

To add files into the index – means to mark them for commit:

git add file

To commit to the local repository, with message “message”

git commit -am "message"

To create a new branch, named newIdea and switch working into that branch:

git branch newIdea
git checkout newIdea

The same, alternatively in one step:

git checkout -b newIdea

To merge changes in newIdea in master branch:

git checkout master
git merge newIdea

In case there are conflicts, we edit the conflict files, resolve the problems and add the files into the index (git add). Then, we commit our changes (git commit).

To create a tag, named newTag

git tag -a newTag

To list tags:

git tag -l

To undo changes in the index, before they are committed:

git reset

To ignore files, add them in the file .gitignore.


Git is an extremely fast source code management tool and the multiple remotes allows users to control sharing. The above description for using git with dropbox allows me a personal source tree, properly versioned, shared to all my machines, as well to select my patches to share with people I collaborate with, using github or Atlassian BitBucket.


Posted on March 20, 2012, in git, Programming and tagged , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: