Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of `git push --mirror`? How do I get my repo back?

Tags:

git

pull

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.

like image 976
Dan Rosenstark Avatar asked Feb 06 '10 15:02

Dan Rosenstark


People also ask

How do I copy a git repository to another git?

You first have to get the original Git repository on your machine. Then, go into the repository. Finally, use the --mirror flag to copy everything in your local Git repository into the new repo.

How do I mirror a repository?

For an existing project, you can set up push mirror from your project's Settings ➔ Repository and searching for the "Push to a remote repository" section. Check the "Remote mirror repository" box and fill in the Git URL of the repository to push to.

What does git push mirror do?

With the Git Mirror option, you can save your valuable commit history with other important refs and remote-tracking branches. The days are gone when developers would manually copy the code from one server to another.


2 Answers

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.

like image 182
VonC Avatar answered Sep 25 '22 14:09

VonC


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.

like image 27
pfalcon Avatar answered Sep 26 '22 14:09

pfalcon