3

How to restore all remote branches from backup (git bundle).

Backup:

$ git bundle create /tmp/dp --all $ git bundle list-heads /tmp/dp | head -n5 f37c9fc7f0ce121568f42fb01390b1862c67f308 refs/heads/master f37c9fc7f0ce121568f42fb01390b1862c67f308 refs/heads/show 9aabc2a4fb18181fee6d0e7e03170a976b6ed49b refs/remotes/origin/NewLayers aef1fc8a416413ee5b7f4370f255ab654b3407ee refs/remotes/origin/elevator bc4c78f94a67857fbd7210ecc5ebcd80ec736b1a refs/remotes/origin/elevator_1 $ git bundle verify /tmp/dp | head -n1 /tmp/dp is okay The bundle contains 65 refs 

Restore:

$ git clone /tmp/dp dp Cloning into dp... $ cd dp $ git branch -a * master remotes/origin/HEAD -> origin/master remotes/origin/master remotes/origin/show 

I tried fetching and pulling but it didn't help.

I also tried to clone with "--mirror" to create bare repo and then clone from it, but the result was the same.

1
  • interesting, I did not know that there is no "remote inheritance". So apparently you would need to create local branches in /tmp/dp tracking the remote ones before cloning tmp/dp. Commented Aug 17, 2012 at 8:55

1 Answer 1

2

The problem is that on cloning the remote branches of the remote repository are not tracked (and the local branches of the remote repo are tracked as remote tracking branches). You didn't say in your question but I guess the (bare) repository created with --mirror included the remote tracking branches.

So the right thing to do is:

git clone --mirror /tmp/dp mkdir dp mv dp.git dp/.git cd dp git config core.bare false git reset --hard 

(i.e. clone with --mirror and undo the implied --bare.) Not pretty but works. Alternatively create a new empty repo using git-init and define /tmp/dp as remote with a line

fetch = +refs/*:refs/* 

instead of the normal

fetch = +refs/heads/*:refs/remotes/remotename/* 

and fetch from it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it is exactly as you said. This has one minor disadvantage - every developer will have to change fetch line in .git/config. However, I found out, that it will be better to backup remote bare repository (firstly making it non-bare, then running "git bundle --all"). Restoring it with simply "clone --mirror" do exactly what I wanted to. Why I want to use "git bundle" to backup bare repo? Single file is better in incremental transferring through network.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.