Git Dropbox

Posted onby admin
  1. Git Dropbox Pull
  2. Git Over Dropbox
  3. Git Dropbox Plugin
  4. Git Dropbox

2016-04-06

Dropbox user id. GitHub Gist: instantly share code, notes, and snippets. 1 git add t1.txt t2.txt p.cpp 2 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.

Git init -bare /Dropbox/git/new-project.git Technically, it's still stored locally on the same machine, but because it's inside our Dropbox folder, it will be automagically synced to the cloud and other linked devices. We still need to 'add' our remote repository to the local one: git remote add dropbox /Dropbox/git/new-project.git. I initialized my dropbox repos by doing a git init -bare. And then in my Desktop's post-commit script, I have a git push -mirror dropbox. This way my desktop and dropbox will always be completely mirrored, which is a good thing.

Dropbox isn’t version control.If you use git to version control your files, andhave co-authors that use Dropbox then here is a way to use the twosystems together.

Make your shared Dropbox folder have a separate repository

Git Dropbox

I’d like my shared Dropbox folder to be a full fledged git repository, andversion control all relevant files there via git. However, git repositoriesusually contain a special .git/ folder in the root. Storing this special.git/ folder in a shared dropbox folder is a recipe for disaster. Anon-git aware collaborator will certainly wreak havoc on it. Further, doingmost git operations (even if they are simply checking the status) will pushnotifications to all your collaborator saying that a few git files havechanged.

This can be annoying (and disastrous). A better alternative is to set up yourshared Dropbox folder to be a git repository, but store the git repository (the.git/ folder) in a separate (non-dropbox) directory.

This creates the git repository in $HOME/.separate-gitroots/foo.git insteadof in ./.git/ as is customary. Now ./.git will be a plain text file (notfolder) that contains the location of the foo.git directory above.

Obviously ./.git will be truly useless to anyone else sharing your Dropboxfolders, so I recommend excluding it from the list of synchronized files. Thedropbox exclude command above does this using Dropbox’sSelective sync feature.

Working on a local copy.

I set up a local copy, away from Dropbox, to work on. This way a collaboratorwho makes changes while I’m working will not overwrite mine, and I can tellthe two changes apart easily. I also use a centralized remote (so I can shareit with git-aware co-authors), but you can do without it (if you know whatyou’re doing.)

Setting up the repositories

Let’s assume you have a git server and created an empty repository on it at [email protected]:foo.We first add this remote into Dropbox, and put your shared files in it:

Now set up a local copy by cloning this repository into ~/foo. Type:

or use your favorite GUI client.You should now have your work in the remote repository [email protected], one clone in Dropbox (for your coauthors to edit) and one local clone in ~/foo for you to edit.(Of course, if you had local files you were already working on in ~/foo, you could have done the git remote add in ~/foo, committed, pushed and then pulled in Dropbox instead.)

Committing changes

When a collaborator make changes in Dropbox, you have to commit and push itfor them, and pull it into your local copy.

After the first commit as your co-author, you can just use --author Coauthorwithout typing the whole email address every time. Also, if you have only oneco-author who will commit in Dropbox, then you can use git config to setuser.name and user.email in the Dropbox repository, and not use --authorabove.

When you make changes:

When you and your co-author simultaneously made changes

No problem. Git handles it painlessly. (I’m omitting the console output of git below for brevity.)

Git Dropbox

The last command may warn you about conflicts (if you and your co-authoredited similar portions of the same file). Follow the instructions displayedby git. Once you’re done, push your changes and pull them into Dropbox asshown in the previous section.

Git

Creating branches for a co-author

Often when when I’m editing my local copy my collaborator makes changes inDropbox simultaneously. For simple changes you can merge them quickly asabove. If there have been more elaborate changes, I usually create a branchand merge it as follows.

  1. Commit and push your collaborators changes to a new branch

  2. Merge your co-authors changes in your local copy. (Or rebase it, if you know what you are doing.)

  3. Pull them in the shared Dropbox folder.

🗫 Comments

  • .git/ location

    Ricardo Lima (2017-12-20 07:56:17 EST)

    Hey Gautam,

    Nice post. Thank you.

    I do not understand this part “This creates the git repository in $HOME/foo/.dropbox.git instead of in ./.git/ as is customary. Now ./.git will be a plain text file (not folder) that contains the location of the true git repository.”

    How does the file $HOME/foo/.dropbox.git is created? With the commands above?Isn’t it created in $HOME/.separate-gitroots/shared.git?Also when you say “Now ./.git will be a plain text file (not folder) that contains the location of the true git repository.”, do you mean “… of the true .git directory?

    Best,

    Ricardo

  • Re: .git/ location

    Gautam Iyer (2017-12-20 12:29:41 EST)

    On 2017-12-20 at 07:56:17 EST, Ricardo Lima wrote

    How does the file $HOME/foo/.dropbox.git is created? With the commands above? Isn’t it created in $HOME/.separate-gitroots/shared.git?

    Apologies, this was a typo which I just fixed.

    Also when you say “Now ./.git will be a plain text file (not folder) that contains the location of the true git repository.”, do you mean “… of the true .git directory?

    Yes. If you do cat .git, you should see something like

    I fixed it above as well, thanks for pointing it out.

    GI

  • Dropbox exclude

    SSJ (2019-02-25 15:56:00 EST)

    Hi,Any idea how to get $ dropbox exclude add .git to work with windows? I have the windows dropbox app installed but cant seem to get the dropbox command to work in command line or gitbashThanks

  • Re: Dropbox exclude

    Gautam Iyer (2019-02-27 15:11:59 EST)

    Any idea how to get $ dropbox exclude add .git to work with windows?

    I don’t know how to do this on windows. But I’m guessing the windows Dropboxclient has a way to exclude files. You just need to get it to exclude the file.git from being synced. But if you don’t, it’s not such a big deal – thefile will be a plain text file which Dropbox can happily sync. Just ask yourcollaborators to avoid modifying / deleting this file.

  • Re: Dropbox exclude

    Anonymous (2020-04-25 03:57:49 EDT)

    To answer SSJ, it appears that the windows version does not have an “equivalent” (in terms of Linux) command line version. The GUI however lets you untick “.git” (chanced on this blog, so this may be dated)

  • Dropbox exclude

    Pete (2020-12-27 03:15:57 EST)

    If you save following line below as a snippet.ps1 file under windows and run it in powershell you might be able to exclude it from syncing.

    Set-Content -Path “C:example_repository.git” -Stream com.dropbox.ignored -Value 1

📮 Leave a comment (Spammers beware: All comments are moderated)

Git Dropbox
Sorry. There was an error submitting your comment. Please try again, or contact me if the problem persists.
Thanks. Your comment was successfully submitted. It will appear here shortly if it isn't spam.

Posted on March 15, 2012 by Paul

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:

Git Dropbox Pull

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

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

Commit changes:

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

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

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

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

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

Git Over Dropbox

Git dropbox sync

Git Dropbox Plugin


Git Dropbox

Show Comments