问题
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.
回答1:
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.
回答2:
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.
回答3:
You can achieve this with git-copy.
git copy /data/Dropbox/backup/that_stuff.git that_stuff.git
来源:https://stackoverflow.com/questions/2213689/opposite-of-git-push-mirror-how-do-i-get-my-repo-back