Reputation: 5933
I've bundled a Git repository using --all
, but I can't figure out how to get a repo back with all the branches.
How do I get all the branches back given a .bundle
file?
Upvotes: 3
Views: 7961
Reputation: 490178
(Note: if your intent was to create a new repository that has, in effect, been "restored from backup", you may want a different set of steps where you never create a remote at all. Setting that aside, here is the answer...)
Add (or use) the file as a (or the) remote, as described in the git bundle
documentation. In the example in the documentation this happens automatically by using the bundle file as the source URL in a git clone
, but you can use git remote add
—see the git remote
documentation for details—to add the bundle file as a new (additional, not-origin
-named) remote to an existing repository.
Example command: git remote add myoldbundle path/to/myold.bundle
Next you may want to edit the file $GIT_DIR/config
to alter the behavior when git fetch
reads the bundle. This will work the same way as any git fetch
, translating their branch names—stored in this bundle file being used as a remote—into your remote-tracking names by default. This is due to that line documented in the git bundle
manual:
[remote "myoldbundle"]
url = path/to/myold.bundle
fetch = refs/heads/*:refs/remotes/origin/*
(or similar), which tells git fetch
: Take their refs/heads/*
names and produce refs/remotes/origin/*
names.
If you change this set of directives, e.g., to read:
fetch = refs/*:refs/*
you will direct your Git to update (without forcing, in this case) all of your references to match all of their references, including tag names, refs/notes/
references, and refs/stash
if that exists. This is similar to the configuration you get if you use git clone --mirror
, which would set the fetch
line to:
fetch = +refs/*:refs/*
Note the leading plus sign here, which means "force": overwrite my branch name (such as refs/heads/master
) with theirs. This is only useful if you never do any work in the repository since it will effectively destroy your branch hash IDs by overwriting them with theirs. (You can retain the old hashes through reflogs, but that's rather tricky, and you will need to know how to deal with your index and work-tree becoming de-synchronized.) Note that a --mirror
clone is automatically --bare
, so that it has no work-tree, so that you cannot get yourself into trouble this way. Be careful if you use +refs/*:refs/*
!
Finally use git fetch
to read the file.
Example command: git fetch myoldbundle
Upvotes: 5