0

In my repo directory /repo when running git branch --all I have:

* foo
  bar
  baz
  remotes/origin/HEAD -> origin/develop
  remotes/origin/qux
  remotes/origin/quux

I now backup and restore the repo:

$ git bundle create /tmp/repo.bundle --all
$ git clone /tmp/repo.bundle /tmp/repo

And now run git branch --all inside /tmp/repo I get something different:

* foo
  remotes/origin/HEAD -> origin/foo
  remotes/origin/bar
  remotes/origin/baz

How can I make it so it is was identical to the first state instead of the origin being the file (/tmp/repo.bundle)? I noticed that the references to qux and quuxx can still be found in the:

$ git bundle list-heads /tmp/repo.bundle
...
refs/heads/foo
refs/heads/bar
refs/heads/baz
refs/remotes/origin/qux
refs/remotes/origin/quux
maxisme
  • 3,974
  • 9
  • 47
  • 97
  • 2
    `git bundle` is like `git clone` or `git fetch` but split up so that you can do it even if you don't have a network connection between two computers. If you *do* have a network connection and were to use `git clone` to copy your repository from your laptop to, say, Fred's laptop, you'd get this same effect. It's supposed to do that, in other words. – torek Apr 21 '22 at 22:06
  • 2
    If you don't want it to do that, you may need `git clone --mirror`, but note that this makes a *bare* clone (specifically a bare mirror clone), which literally cannot be used for anything else. So you probably don't want that after all. – torek Apr 21 '22 at 22:08
  • 2
    If you want to go beyond *that*, you'll need to learn about the internals of Git. But the point here is that `git bundle` is not a backup system (nor is Git). Use a backup system to make backups. – torek Apr 21 '22 at 22:08
  • Ahh okay thank you. Can you reccomend a backup system - I am worrried about backing up maybe a not very clean .git folder with locks or something. – maxisme Apr 21 '22 at 22:43
  • On my Mac, I let Time Machine do the backups. If the backup happens while Git is running, the locks do get backed-up, but this is not a big deal as Git will let you "break" the lock later if necessary. – torek Apr 21 '22 at 23:01
  • Ah okay, How does "break"ing the lock work? – maxisme Apr 22 '22 at 08:51
  • Basically, if you restore a repository from a backup and Git operations tell you that they can't proceed because of some lock file (usually `index.lock` although there are others), you know—since you just restored the repo—that nothing else is doing stuff *in* the repo and therefore you can simply remove the lock file. Git even prints some advice about this at the time it gets stuck. – torek Apr 22 '22 at 09:05

0 Answers0