7

I am having great success with git push --mirror to make backup copies to a bare repo. But after search on SO and elsewhere, I cannot find a way to clone the thing locally with all branches. I do not want to use git clone since I don't want my local repo to know about the bare repo. If I use git pull it only brings down the HEAD branch.

Guessing:

git pull /data/Dropbox/backup/that_stuff.git *

gets me nowhere, of course.

How do I get the entire repo with all branches back again? I realize I could probably just copy the bare repo to my .git directory, but that seems like a bad idea.

Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
  • So I guess the `git bundle` from 2 weeks ago is no longer to your liking? (http://stackoverflow.com/questions/2129214/backup-a-local-git-repository/2129286#2129286) – VonC Feb 06 '10 at 16:24
  • 1
    @VonC thanks so much for that. Although you did answer the question expertly, it turns out that it makes little sense to backup to a GIT bundle in a DropBox. It adds too much traffic (to the server) and has no advantage. MIrror is also way faster. Now if I could just resolve this one last problem :) – Dan Rosenstark Feb 06 '10 at 16:31
  • Just completed my answer with the right '`*`' you were looking for? – VonC Feb 06 '10 at 16:49
  • Almost a year later: bundles are the ONLY thing that make sense on dropbox. If you use `git gc` the bundles are tiny, too. – Dan Rosenstark Dec 27 '10 at 05:10
  • @Yar could you elaborate on your last comment.. i'm in a similar situation, prefer bare repo over bundle... want to know your learning – user Jun 26 '11 at 19:26
  • @buffer, you cannot roll back a DIRECTORY in dropbox (last time I checked). You can only roll back files. Also, the internal pieces of a bare git repo will get screwed up if you try to sync from more than one computer to a dropbox. So either use unfuddle.com or use git bundles with dropbox, basically. – Dan Rosenstark Jun 28 '11 at 14:58
  • @Yar I've put all my git stuff in a truecrypt file container that gets uploaded as a binary to dropbox. Would that still be an issue if I try to sync it with multiple computers – user Jun 28 '11 at 15:43
  • @buffer, AFAIK that should be fine, since the truecrypt container is one big file, so Dropbox will not try to sync the individual pieces nor run into conflicts on individual files. That said, you should check out unfuddle.com which does have small free repos. – Dan Rosenstark Jun 29 '11 at 20:24

3 Answers3

2

Try git fetch instead of git pull

Since git pull is there to fetch a branch and merge it to a local branch, it wouldn't make alot of sense trying to merge all remote branches to a local branches.

$ git fetch a-repo_url

The above command copies all branches from the remote refs/heads/ namespace and stores them to the local refs/remotes/remoteRpo/ namespace, unless the branch.<name>.fetch option is used to specify a non-default refspec..
Try:

$ git fetch a-repo-url +refs/heads/*:refs/heads/*

could force fetching all heads for all branches.
See this SO question.


The OP yar reports:

git pull /data/Dropbox/backup/mjdj.git/ +refs/heads/*:refs/heads/*

works.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Tried that. GIT responds `* branch HEAD -> FETCH_HEAD `... so it just gets that one. – Dan Rosenstark Feb 06 '10 at 16:29
  • Tried that last one with the asterisks... fatal: Refusing to fetch into current branch refs/heads/master of non-bare repository – Dan Rosenstark Feb 06 '10 at 16:53
  • @yar: Maybe it needs a remote reference (http://www.kernel.org/pub/software/scm/git/docs/git-remote.html), but that would mean "making your local repo to know about the bare repo", which is not what you want. – VonC Feb 06 '10 at 16:54
  • Sorry this did it! Thanks `git pull /data/Dropbox/backup/mjdj.git/ +refs/heads/*:refs/heads/*` ... if you can update your answer I'll mark it – Dan Rosenstark Feb 06 '10 at 16:54
  • 2
    totally. that's what the songs are for. – Dan Rosenstark Feb 06 '10 at 17:35
  • 1
    Even more specific if you want *all* refs you can do git pull /data/Dropbox/backup/mjdj.git/ +refs/*:refs/* – taxilian Jan 24 '11 at 06:07
  • 1
    My understanding is that `git fetch a-repo-url +refs/heads/*:refs/heads/*` will usually only work on a bare repo. Otherwise you'll get the error Yar mentions because [fetch cannot update the branch you're currently on](http://stackoverflow.com/questions/2236743/git-refusing-to-fetch-into-current-branch/2236805#2236805). Using `pull` instead should work, but be prepared for merge conflicts unless you're sure it'll fast-forward. – kynan Sep 23 '11 at 15:40
1

There's also (now?) git clone --mirror. But man says:

   --mirror
       Set up a mirror of the remote repository. This implies --bare.

https://git.wiki.kernel.org/index.php/GitFaq#How_do_I_clone_a_repository_with_all_remotely_tracked_branches.3F describes how to turn bare repo into non-bare.

pfalcon
  • 6,724
  • 4
  • 35
  • 43
-1

You can achieve this with git-copy.

git copy /data/Dropbox/backup/that_stuff.git that_stuff.git
Quanlong
  • 24,028
  • 16
  • 69
  • 79