1133
votes

Is it possible to use Git and Dropbox together?

10
  • 2
    See also Bradley Wright's tutorial.
    – Ron Romero
    Commented Apr 1, 2011 at 16:08
  • 40
    If you are just a small team (up to 5 I think), then BitBucket provides free hosting for private repositories. Ironically I then have my local repo on DropBox, just in case I move between computers when I'm working on something. Commented Mar 31, 2012 at 17:47
  • 13
    I'm not sure that your versioning redundancy is ironic, but it is probably quite useful Commented Apr 29, 2012 at 17:26
  • 3
    This question is unclear. What does it mean to use these tools together "effectively"? It's also too broad, and likely to generate opinionated answers.
    – user456814
    Commented Apr 2, 2014 at 6:08
  • 3
    This question is being discussed on meta: meta.stackoverflow.com/questions/401924/…
    – 10 Rep
    Commented Oct 8, 2020 at 17:44

20 Answers 20

1406
votes

I think that Git on Dropbox is great. I use it all the time. I have multiple computers (two at home and one at work) on which I use Dropbox as a central bare repository. Since I don’t want to host it on a public service, and I don’t have access to a server that I can always SSH to, Dropbox takes care of this by syncing in the background (very doing so quickly).

Setup is something like this:

~/project $ git init
~/project $ git add .
~/project $ git commit -m "first commit"
~/project $ cd ~/Dropbox/git

~/Dropbox/git $ git init --bare project.git
~/Dropbox/git $ cd ~/project

~/project $ git remote add origin ~/Dropbox/git/project.git
~/project $ git push -u origin master

From there, you can just clone that ~/Dropbox/git/project.git directory (regardless of whether it belongs to your Dropbox account or is shared across multiple accounts) and do all the normal Git operations—they will be synchronized to all your other machines automatically.

I wrote a blog post “On Version Control” in which I cover the reasoning behind my environment setup. It’s based on my Ruby on Rails development experience, but it can be applied to anything, really.

29
  • 62
    I wonder what'll happen if you push to the dropbox bare repo from two machines at the same time. If it'll cause a modification in one of git's internal files, dropbox will show you there's a conflict -- but what do you do then? Just pick one of the versions, and then push again from both machines (one by one)?
    – dubek
    Commented May 13, 2010 at 11:12
  • 165
    @dubek: You'll probably end up corrupting the shared bare repo. This approach is only suitable for a small team (two in my case) where people can just shout over their cubicle walls: "Hey! Nobody push! I'm pushing now!".
    – Ates Goral
    Commented Sep 13, 2010 at 20:04
  • 51
    @Ates: At least git is decentralized, so if you manage to corrupt things you can restore it from someone's local copy. If you have a big team, chances are that there's enough cash for a hosted repo somewhere.
    – rdrey
    Commented Oct 21, 2010 at 5:37
  • 7
    Git is clever that is uses hashes for its internal data files so it will be very rare that you will conflict it's internal state. It's like having multiple people access a git location that uses ssh, there are no conflicts. It was designed that way. So you will be fine with 2 people pushing to a repository at the same time on dropbox. We've done this.
    – dalore
    Commented Feb 17, 2011 at 12:43
  • 15
    @kilaka: Using a bare repo, only Git metadata gets synced. If you put your local repo directly into your DropBox folder then you get a lot more DropBox traffic every time you checkout a different branch as all your code files vanish / appear / change. It's not necessarily an issue but it does increase the risk that you turn off your machine before a (now potentially much longer) sync is complete, thereby causing you corruption issues. Also, a bare repo takes up less space, which is significant given DropBox is only free up to 2GB (at time of writing).
    – Holf
    Commented Jan 18, 2013 at 11:49
135
votes

The right way to do this is use git-remote-dropbox: https://github.com/anishathalye/git-remote-dropbox

Creating your own bare repo in Dropbox causes a lot of problems. Anish (the creator of the library) explains it best:

The root cause of these problems is that the Dropbox desktop client is designed for syncing files, not Git repositories. Without special handling for Git repositories, it doesn’t maintain the same guarantees as Git. Operations on the remote repository are no longer atomic, and concurrent operations or unlucky timing with synchronization can result in a corrupted repository.

Traditional Git remotes run code on the server side to make this work properly, but we can’t do that.

Solution: It is possible to solve this properly. It is possible to use Git with Dropbox and have the same safety and consistency guarantees as a traditional Git remote, even when there are multiple users and concurrent operations!

For a user, it’s as simple as using git-remote-dropbox, a Git remote helper that acts as a transparent bidirectional bridge between Git and Dropbox and maintains all the guarantees of a traditional Git remote. It’s even safe to use with shared folders, so it can be used for collaboration (yay unlimited private repos with unlimited collaborators!).

With the remote helper, it’s possible to use Dropbox as a Git remote and continue using all the regular Git commands like git clone, git pull, and git push, and everything will just work as expected.

6
  • 8
    I'm happy to see that someone posted about git-remote-dropbox on this StackOverflow question. I wonder if there's any way to get this response closer to the top. The method recommended by the current accepted answer is pretty dangerous and can result in repository corruption.
    – fwenom
    Commented Mar 2, 2016 at 2:59
  • 1
    that's really cool. i will definitely check it out. but when i move from one dev box to another, and want to keep working on a sync'ed repo, this method will only work if i always commit my work when i leave machine A, and want to pick up where i left off on machine B. am i right? if so, this is not ideal, as it would lead to a flurry of "interim" commits, which one could argu will pollute the commit history of the repo. maybe i just can't have my cake and eat it too! Commented Mar 21, 2016 at 8:56
  • 1
    @bhuBouevidya No that's not true. You don't need to commit your work for the changes to by synced. As long as the files are saved the files will be synced. Basically if you have a bunch of modified files on one machine, the modifications will sync over to the other because Dropbox just cares about what has been saved to disk.
    – b.lyte
    Commented Mar 21, 2016 at 18:02
  • 2
    @clu: Yes you must commit your work and push. All that git-remote-dropbox does is act as a git remote helper. Just like other remotes, your local commits will not be pushed to the remote until a push is done. The way to get locally modified files to into the local repository so that they can be pushed is by doing a commit. Dropbox will not know anything about your files not in the repository.
    – Ants
    Commented Dec 31, 2016 at 20:53
  • 2
    Just curious if git-remote-dropbox is cross-platform... I see it uses python, and I know certain other python stuff for Dropbox is not cross-platform, for instance on OS X the command line stuff is not compatible.
    – Michael
    Commented Jan 16, 2017 at 23:22
91
votes

This answer is based on Mercurial experience, not Git, but this experience says using Dropbox this way is asking for corrupt repositories if there's even a chance that you'll be updating the same Dropbox-based repository from different machines at various times (Mac, Unix, Windows in my case).

I don't have a complete list of the things that can go wrong, but here's a specific example that bit me. Each machine has its own notion of line-ending characters and how upper/lower case characters are handled in file names. Dropbox and Git/Mercurial handle this slightly differently (I don't recall the exact differences). If Dropbox updates the repository behind Git/Mercurial's back, presto, broken repository. This happens immediately and invisibly, so you don't even know your repository is broken until you try to recover something from it.

After digging out from one mess doing things this way, I've been using the following recipe with great success and no sign of problems. Simply move your repository out of Dropbox. Use Dropbox for everything else; documentation, JAR files, anything you please. And use GitHub (Git) or Bitbucket (Mercurial) to manage the repository itself. Both are free so this adds nothing to the costs, and each tool now plays to its strengths.

Running Git/Mercurial on top of Dropbox adds nothing except risk. Don't do it.

5
  • 13
    I feel that the git repository is robust enough not to corrupt itself. My experience (over a year of usage, mostly single-user, cross-platform, cross-computer, multiple devs), is that git's repo is not easily corrupted. In git, only information is added to the repository, existing files are left alone 99.9% of the time (mutable files are mostly easy to inspect manually). I've sometimes seen cases where a branch pointer was overwritten, but this can be easily seen (i.e. "branch (XXX's conflicted copy)") and removed (no real fixing needed, actually).
    – Egon
    Commented Jan 24, 2012 at 21:36
  • 1
    @tc: You are right, during garbage collection, non-reachable information is removed in git. However, I guess that for most practical cases, this doesn't harm robustness: only unreachable information older than 2 weeks is affected (which is ample time for DropBox to synchronize). And at that moment of such a conflict, I suspect most information will be available both in packed and unpacked form.
    – Egon
    Commented Mar 10, 2013 at 19:11
  • I think that the code-sharing scenario with no central repo (descibed in an answer below) would save one from possible corruptions because of concurrent updates to directory in dropbox. If one needs a central repo, it could be managed separately (and outsied of dropbox); dropbox would hold personal working repos (which is also convenient because you could update/pull from time to time from the someone else's source repo in your team which you based work on). (I'm actually contemplating using darcs in such a setting.) Commented Apr 1, 2013 at 12:11
  • 5
    +1 If you don't want to host your repositories in public, use Bitbucket, private repos are free for teams up to 5 users. Commented Sep 25, 2013 at 19:47
  • One things I've noticed between a Windows machine and an OSX machine is file permissions can cause diff issues. You can turn off permissions in Git using: "git config core.fileMode false"
    – devdrc
    Commented Jan 29, 2020 at 18:10
17
votes

I didn't want to put all my projects under one Git repository, nor did I want to go in and run this code for every single project, so I made a Bash script that will automate the process. You can use it on one or multiple directories - so it can do the code in this post for you or it can do it on multiple projects at once.

#!/bin/sh
# Script by Eli Delventhal
# Creates Git projects for file folders by making the origin Dropbox. You will need to install Dropbox for this to work.

# Not enough parameters, show help.
if [ $# -lt 1 ] ; then

cat<<HELP
projects_to_git.sh -- Takes a project folder and creates a Git repository for it on Dropbox

USAGE:
    ./projects_to_git.sh file1 file2 ..

EXAMPLES:
    ./projects_to_git.sh path/to/MyProjectDir
        Creates a git project called MyProjectDir on Dropbox

    ./projects_to_git.sh path/to/workspace/*
        Creates a git project on Dropbox for every folder contained within the workspace directory, where the project name matches the folder name

HELP
    exit 0
fi

# We have enough parameters, so let's actually do this thing.

START_DIR=$(pwd)

# Make sure we have a connection to Dropbox
cd ~
if [ -s 'Dropbox' ] ; then
    echo "Found Dropbox directory."
    cd Dropbox
    if [ -s 'git' ] ; then
        echo "    Dropbox Git directory found."
    else
        echo "    Dropbox Git directory created."
        mkdir git
    fi
else
    echo "You do not have a Dropbox folder at ~/Dropbox! Install Dropbox. Aborting..."
    exit 0
fi

# Process all directories matching the passed parameters.
echo "Starting processing for all files..."
for PROJ in $*
do
    if [ -d $PROJ ] ; then
        PROJNAME=$(basename $PROJ)
        echo "  Processing $PROJNAME..."

        # Enable Git with this project.
        cd $PROJ
        if [ -s '.git' ] ; then
            echo "    $PROJNAME is already a Git repository, ignoring..."
        else
            echo "    Initializing Git for $PROJNAME..."
            git init -q
            git add .
            git commit -m "Initial creation of project." -q

            # Make the origin Dropbox.

            cd ~/Dropbox/git
            if [ -s $PROJNAME ] ; then
                echo "    Warning! $PROJNAME already exists in Git! Ignoring..."
            else
                echo "    Putting $PROJNAME project on Dropbox..."
                mkdir $PROJNAME
                cd $PROJNAME
                git init -q --bare
            fi

            # Link the project to the origin
            echo "    Copying local $PROJNAME to Dropbox..."
            cd $PROJ
            git remote add origin "~/Dropbox/git/$PROJNAME"
            git push -q origin master
            git branch --set-upstream master origin/master
        fi
    fi
done

echo "Done processing all files."
cd $START_DIR
16
votes

It is now 2015, and as of three days ago, a new tool based on Dropbox API v2 has been created to safely use git on Dropbox. It works against the API rather than using the desktop client, and correctly handles multiple simultaneous pushes to a repository hosted in a shared folder.

Once configured, it allows one to set up a git remote exactly like any other git remote.

git clone "dropbox::/path/to/repo"
git remote add origin "dropbox::/path/to/repo"
0
15
votes

With regards to small teams using Dropbox:

If each developer has their own writable bare repository on Dropbox, which is pull only to other developers, then this facilitates code sharing with no risk of corruption!

Then if you want a centralized 'mainline', you can have one developer manage all the pushes to it from their own repo.

1
  • 1
    Great so much! Also, to protect repo corruption from multiple writes you easily could make MULTIPLE repos and sync only their .git folders! All you need in a moment - is to pull from desired origin! Great P-to-P man! You understand decentralized git's philosophy! Commented Aug 1, 2014 at 6:43
15
votes

I don't think that using Git and Dropbox is the way to go... Just think about the features of both:

Git:

  • Allows you to have a central repository
  • Allows you to have your own repository with your own changes
  • Allows you to send and receive changes from the central repository
  • Allows multiple persons to change the same files and them merges them or asks you to merge them if it can't do it
  • Has web and desktop clients to allow access to the central repository

Dropbox:

  • Keeps everything in a central repository
  • Allows you to have your own versions of the files in the server
  • Forces you to send and receive changes from the central repository
  • If multiple persons change the same files, the first file committed is replaced with later commits, and no merge occurs which is troublesome (and definitely its biggest disadvantage)
  • Has web and desktop clients to allow access to the central repository.

And if you're worried with sharing some of your files, why not cipher them? And then you could get the biggest advantage of Dropbox to Git, that is, to have public and private files...

4
  • Dropbox is just a good option for a central repo. If placed in a shared folder it even works for groups.
    – mac
    Commented Feb 4, 2011 at 12:02
  • 1
    Yes, but you won't have the same merging features as in git, in fact if someone is editing the same file as yours, and he saves the file after you, your changes are lost, unless you go to the web interface and download the old version (your version).
    – Coyote21
    Commented Feb 5, 2011 at 21:53
  • 8
    This is wrong. Dropbox doesn't drop conflicts. It mangles the filename of one edit, and uses the other for continuity. You can manually merge them yourself if you like. It's a good compromise, and doesn't lose data. dropbox.com/help/36
    – Clueless
    Commented Feb 16, 2011 at 19:13
  • 6
    Yes but since this is about code, the less time I spend merging files the more code I can produce, and in a normal codebase it can be hundreds of conflicts at one time, depending of the project dimensions, and it would be a nightmare to merge then one by one, even with the help of a merge tool like WinMerge (or something alike).
    – Coyote21
    Commented Feb 21, 2011 at 19:03
9
votes

I use Mercurial (or Git) + TrueCrypt + Dropbox for encrypted remote backups.

The coolest thing is that Dropbox does NOT sync the entire TrueCrypt container if you modify a small portion of your code. The sync time is roughly proportional to the amount of changes. Even though it's encrypted, the combination of TrueCrypt + Dropbox makes excellent usage of block cipher + block level sync.

Secondly, a monolithic encrypted container not just adds security, it also reduces chances of repository corruption .

Caution: However you have to be very careful about not having the container mounted while Dropbox is running. It can also be a pain to resolve conflicts if 2 different clients check-in different versions to the container. So, it's practical only for a single person using it for backups, not for a team.

Setup:

  • Create a Truecrypt container (multiple Gigabyte is fine)
  • Under Truecrypt preferences, uncheck preserve modification timestamp*.
  • Create a repo as mentioned above by Dan ( https://stackoverflow.com/a/1961515/781695 )

Usage:

  • Quit Dropbox
  • Mount the container, push your changes, unmount
  • Run dropbox

P.S. Unchecking the preserve modification timestamp tells dropbox that the file has been modified and it should be sync'd. Note that mounting the container modifies the timestamp even if you don't change any file in it. If you don't want that to happen, simply mount the volume as read-only

2
  • Would it be much different if using a macos encrypted .dmg file image, would the sync time be still roughy proportional to the changes?
    – IBrum
    Commented Feb 24, 2018 at 16:08
  • @IBrum Sorry, I don't haven't tried it with a .dmg file
    – user
    Commented Mar 29, 2018 at 16:55
7
votes

We use this method (creating a bare repository in Dropbox) on a share folder.

A small group of developers can pull from that bare synced repository and create a local clone. Once the unit of work is done, we push back to origin.

One thing I'm missing is a good way to have an e-mail sent with the change-set information once a push to origin occurs. We are using Google Wave to manually keep track of changes.

0
7
votes

I love the answer by Dan McNevin! I'm using Git and Dropbox together too now, and I'm using several aliases in my .bash_profile so my workflow looks like this:

~/project $ git init
~/project $ git add .
~/project $ gcam "first commit"
~/project $ git-dropbox

These are my aliases:

alias gcam='git commit -a -m'
alias gpom='git push origin master'
alias gra='git remote add origin'
alias git-dropbox='TMPGP=~/Dropbox/git/$(pwd | awk -F/ '\''{print $NF}'\'').git;mkdir -p $TMPGP && (cd $TMPGP; git init --bare) && gra $TMPGP && gpom'
1
  • I would probably not use last thing as an alias, rather a shell script. Otherwise, I like this very much. Extra credit for awk usage.
    – pauljohn32
    Commented Nov 29, 2019 at 16:05
6
votes

I've been using Mercurial in the recommended manner and urge that you be cautious, especially if any of the machines differ. The Dropbox fora are full of complaints of mysterious filename case problems turning up spontaneously. Hg (and I presume Git) won't notice or complain during routine checkins and you'll only hear about the corruption when it complains of a corrupt repo when you try to use it for real. Bad news. Wish I could be more specific about the problem and its workarounds; I'm still trying to dig out from this mess myself.

1
  • git do much more checking for corruptions than others by design. So at least you will know when that happens and can correct the problem.
    – Anders
    Commented Sep 11, 2012 at 20:15
6
votes

There's also an open source project (a collection of cross platform [Linux, Mac, Win] scripts) that does all the nitty-gritty details of the repository management with a handful (3-4) of commands.

https://github.com/karalabe/gitbox/wiki

Sample usage is:

$ gitbox create myapp
Creating empty repository...
Initializing new repository...
Repository successfully created.

$ gitbox clone myapp
Cloning repository...
Repository successfully cloned.

After which normal git usage:

$ echo “Some change” > somefile.txt
$ git add somefile.txt
$ git commit –m “Created some file”
$ git push

Check the project wiki and the manuals for full command reference and tutorials.

4
votes

I store my non-Github repo's on Dropbox. One caveat I ran into was syncing after a reinstall. Dropbox will download the smallest files first before moving to the larger ones. Not an issue if you start at night and come back after the weekend :-)

My thread - http://forums.dropbox.com/topic.php?id=29984&replies=6

4
votes

Now in 2014, I have been using Git and Dropbox for about one year and a half without problem. Some points though:

  • All my machines using Dropbox are on Windows, different versions (7 to 8) + 1 mac.
  • I do not share the repository with someone else, so I am the only one to modify it.
  • git push pushes to a remote repository, so that if it ever gets corrupted, I can easily recover it.
  • I had to create aliases in C:\Users with mklink /D link target because some libraries were pointed to absolute locations.
4
votes

Another approach:

All the answers so far, including @Dan answer which is the most popular, address the idea of using Dropbox to centralize a shared repository instead of using a service focused on git like github, bitbucket, etc.

But, as the original question does not specify what using "Git and Dropbox together effectively" really means, let's work on another approach: "Using Dropbox to sync only the worktree."

The how-to has these steps:

  1. inside the project directory, one creates an empty .git directory (e.g. mkdir -p myproject/.git)

  2. un-sync the .git directory in Dropbox. If using the Dropbox App: go to Preferences, Sync, and "choose folders to sync", where the .git directory needs to get unmarked. This will remove the .git directory.

  3. run git init in the project directory

It also works if the .git already exists, then only do the step 2. Dropbox will keep a copy of the git files in the website though.

Step 2 will cause Dropbox not to sync the git system structure, which is the desired outcome for this approach.

Why one would use this approach?

  • The not-yet-pushed changes will have a Dropbox backup, and they would be synced across devices.

  • In case Dropbox screws something up when syncing between devices, git status and git diff will be handy to sort things out.

  • It saves space in the Dropbox account (the whole history will not be stored there)

  • It avoids the concerns raised by @dubek and @Ates in the comments on @Dan's answer, and the concerns by @clu in another answer.

The existence of a remote somewhere else (github, etc.) will work fine with this approach.

Working on different branches brings some issues, that need to be taken care of:

  • One potential problem is having Dropbox (unnecessarily?) syncing potentially many files when one checks out different branches.

  • If two or more Dropbox synced devices have different branches checked out, non committed changes to both devices can be lost,

One way around these issues is to use git worktree to keep branch checkouts in separate directories.

2
  • As someone who's working on files that it would be nice to version control, but also be editable on an iPad (via Dropbox syncing), this answer covers that use case.
    – Vagari
    Commented May 18, 2020 at 1:42
  • 1
    Quick followup, current Dropbox behavior is different. Simply removing and telling Dropbox to not sync means the opposite, stays in cloud, removes from local. But there's a superuser answer with a solution. superuser.com/a/1527145/109561 In my case (on Mac) the following flags the file for ignoring, xattr -w com.dropbox.ignored 1 /path/to/somewhere.
    – Vagari
    Commented May 18, 2020 at 2:16
3
votes

I like the top-voted answer by Dan McNevin. I ended up doing the sequence of git commands too many times and decided to make a script. So here it is:

#!/bin/bash

# Usage
usage() {
    echo "Usage: ${0} -m [ master-branch-directory ] -r [ remote-branch-directory ] [ project-name ]"
    exit 1
}

# Defaults
defaults() {
    masterdir="${HOME}/Dropbox/git"
    remotedir="${PWD}"
    gitignorefile="# OS generated files #\n\n.DS_Store\n.DS_Store?\n.Spotlight-V100\n.Trashes\nehthumbs.db\nThumbs.db"
}

# Check if no arguments
if [ ${#} -eq 0 ] ; then
    echo "Error: No arguments specified"
    usage
fi

#Set defaults
defaults

# Parse arguments
while [ ${#} -ge 1 ]; do
    case "${1}" in
        '-h' | '--help' ) usage ;;
        '-m' )
            shift
            masterdir="${1}"
            ;;
        '-r' )
            shift
            remotedir="${1}"
            ;;
        * )
            projectname="${1##*/}"
            projectname="${projectname%.git}.git"
            ;;
    esac
    shift
done

# check if specified directories and project name exists
if [ -z "${projectname}" ]; then
    echo "Error: Project name not specified"
    usage
fi

if [ ! -d "${remotedir}" ]; then
    echo "Error: Remote directory ${remotedir} does not exist"
    usage
fi

if [ ! -d "${masterdir}" ]; then
    echo "Error: Master directory ${masterdir} does not exist"
    usage
fi

#absolute paths
remotedir="`( cd \"${remotedir}\" && pwd )`"
masterdir="`( cd \"${masterdir}\" && pwd )`"

#Make master git repository
cd "${masterdir}"
git init --bare "${projectname}"

#make local repository and push to master
cd "${remotedir}"
echo -e "${gitignorefile}" > .gitignore # default .gitignore file
git init
git add .
git commit -m "first commit"
git remote add origin "${masterdir}/${projectname}"
git push -u origin master

#done
echo "----- Locations -----"
echo "Remote branch location: ${remotedir}"
echo "Master branch location: ${masterdir}"
echo "Project Name: ${projectname}"

The script only requires a project name. It will generate a git repository in ~/Dropbox/git/ under the specified name and will push the entire contents of the current directory to the newly created origin master branch. If more than one project name is given, the right-most project name argument will be used.

Optionally, the -r command argument specifies the remote branch that will push to the origin master. The location of the project origin master can also be specified with the -m argument. A default .gitignore file is also placed in the remote branch directory. The directory and .gitignore file defaults are specified in the script.

3
votes

For my 2 cents Dropbox only makes sence for personal use where you don't want to bother getting a central repo host. For any professional development you'll probably create more problems than you'll solve, as have been mentioned several times in the thread already, Dropbox isn't designed for this use case. That said, a perfectly safe method to dump repositories on Dropbox without any third-party plugins or tools is to use bundles. I have the following aliases in my .gitconfig to save typing:

[alias]
        bundle-push = "!cd \"${GIT_PREFIX:-.}\" && if path=\"$(git config remote.\"$1\".url)\" && [ \"${path:0:1}\" = / ]; then git bundle create \"$path\" --all && git fetch \"$1\"; else echo \"Not a bundle remote\"; exit 1; fi #"
        bundle-fetch = "!cd \"${GIT_PREFIX:-.}\" && if path=\"$(git config remote.\"$1\".url)\" && [ \"${path:0:1}\" = / ]; then git bundle verify \"$path\" && git fetch \"$1\"; else echo \"Not a bundle remote\"; exit 1; fi #"
        bundle-new = "!cd \"${GIT_PREFIX:-.}\" && if [ -z \"${1:-}\" -o -z \"${2:-}\" ]; then echo \"Usage: git bundle-new <file> <remote name>\"; exit 1; elif [ -e \"$2\" ]; then echo \"File exist\"; exit 1; else git bundle create \"$2\" --all && git remote add -f \"$1\" \"$(realpath \"$2\")\"; fi #"

Example:

# Create bundle remote (in local repo)
$ git bundle-new dropbox ~/Dropbox/my-repo.bundle
# Fetch updates from dropbox
$ git bundle-fetch dropbox
# NOTE: writes over previous bundle. Thus, roughly equivalent to push --force --prune --all
$ git bundle-push
2
votes

I have faced a similar issue and have created a small script for the same. The idea is to use Dropbox with Git as simply as possible. Currently, I have quickly implemented Ruby code, and I will soon add more.

The script is accessible at https://github.com/nuttylabs/box-git.

0
votes

Without using third-party integration tools, I could enhance the condition a bit and use DropBox and other similar cloud disk services such as SpiderOak with Git.

The goal is to avoid the synchronization in the middle of these files modifications, as it can upload a partial state and will then download it back, completely corrupting your git state.

To avoid this issue, I did:

  1. Bundle my git index in one file using git bundle create my_repo.git --all.
  2. Set a delay for the file monitoring, eg 5 minutes, instead of instantaneous. This reduces the chances DropBox synchronizes a partial state in the middle of a change. It also helps greatly when modifying files on the cloud disk on-the-fly (such as with instantaneous saving note-taking apps).

It's not perfect as there is no guarantee it won't mess up the git state again, but it helps and for the moment I did not get any issue.

0
votes

On MacOS you may also just stop Dropbox, make your changes and then relaunch Dropbox. I am using the following combination and am quite happy with it:

In both (your local git managed project directory and your remote git repository located on Dropbox) run the following command to disable auto-packing (which is the main problem with dropbox syncing)

git config --global gc.auto 0

Then from time to time, compress the repositories with dropbox disabled. For example I do the following in my bash-build-script whenever I make new releases of my apps.

osascript -e "tell application \"Dropbox\" to quit"

# Compress local
git gc --prune=now; git repack -a -d

# Compress remote
REPOS_DIR_REMOTE=`git remote get-url --push origin`
cd "${REPOS_DIR_REMOTE}"
git gc --prune=now; git repack -a -d

osascript -e "tell application \"Dropbox\" to launch"
osascript -e "display notification with title \"Compress Done\""

Not the answer you're looking for? Browse other questions tagged or ask your own question.