2

Dropbox tends to have problems with git files. Making duplicates etc. However, I would like it to back up some elements that I may not necessarily include in my git repositories and also track changes that I haven't yet commit to git.

I have a great solution for this when it's a brand new git repo (git init)

I change directories to the project folder in dropbox and in a terminal:

git --git-dir=~/git_storage/my.git --work-tree=. init && echo "gitdir: ~/git_storage/my.git" > .git

It works exactly as I would expect. It replaces the .git folder in the working directory with a text file .git containing the directory in which the git files are actually stored. All of this - outside of dropbox. Leaving only the .git text file to be synced.

However, I'd like to know how to have the same setup (.git directory outside of dropbox) for a cloned or, already existing repository.

Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
  • Possible alternative: http://stackoverflow.com/a/1961515/227176 – Sukima Jun 26 '15 at 21:20
  • possible duplicate of [Using git with a project in a Dropbox folder](http://stackoverflow.com/questions/19550657/using-git-with-a-project-in-a-dropbox-folder) – Sukima Jun 26 '15 at 21:21
  • Both of those questions presume that the .git folder is in Dropbox. This isn't what I'm asking at all. Please review the question again, I've updated to add some more clarity. – Brandon Bertelsen Jun 26 '15 at 21:30
  • Have you tried setting the `GIT_DIR` and `GIT_WORK_TREE` environment variables before running your `git clone` command? Not sure if clone will respect those. – charlesreid1 Jun 27 '15 at 04:38
  • Alternatively, you might try the `--separate-git-dir=` option of `git clone`. From `git help clone`: "Instead of placing the cloned repository where it is supposed to be, place the cloned repository at the specified directory, then make a filesytem-agnostic Git symbolic link to there. The result is Git repository can be separated from working tree." – charlesreid1 Jun 27 '15 at 04:43
  • Why not simply move the ```.git``` directory somewhere and then create a symbolic link in Dropbox to the new location? – mattmilten Jun 27 '15 at 09:44

1 Answers1

2

If the repo already exists in Dropbox (ie, you cannot clone it with the --separate-git-dir=<git dir> mentioned by charlesreid1), you can:

  • move the .git outside of DropBox
  • set GIT-DIR to the new path of the .git

That way, you go on working in your Git repo (whose working tree remains in Dropbox like before), but your git commands will use the .git repo which is now outside Dropbox (even though I had bad experiences before, and use git bundle instead).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250