-1

I am trying to backup entire git code history with all branches.

I have use git clone {url}, and it only clone the master/main branch.

I then use git clone {url} --mirror and also git clone {url} --bare, but it does not have the code inside.

What command should i use to backup entire git code with branches

vincentsty
  • 2,963
  • 7
  • 34
  • 51
  • What do you exactly mean by "backup"? A `git clone` does not "backup". – Gino Mempin Jul 01 '22 at 00:28
  • Note that `git clone` copies *all the commits* but *none* of the branches (the one branch in the new clone is a *new* branch, that belongs to the clone only). The branches become *remote-tracking names* instead. Using `git clone --mirror` copies all the commits and all the branches, but the resulting clone is a "bare" clone in which you cannot do any work (on purpose). None of these is a "backup" since backups have a different *goal* from cloning, but any kind of clone is generally good enough if what you want is to preserve all the *commits*. – torek Jul 01 '22 at 06:25
  • To make a true backup (e.g., for "computer burns down inside the building when it burns down" purposes), use a backup system; store the backups off-site so that they don't also burn down when the building burns down. A mirror clone will often serve well as a backup for "computer disk drive fails, but computer as a whole, and building, is still fine" purposes, but you do need to know exactly how to *restore* it later. True backup software *comes with* restoring systems. – torek Jul 01 '22 at 06:25
  • People sometimes use mirror clones (or bundles—see the duplicate) as cheap ways of approximating a true backup, and that works fine; just remember that it's not a "true" backup and doesn't handle every case as efficiently. That might be what you want—you don't want to pay the extra costs, whatever they are, for true backup that you never wind up needing! – torek Jul 01 '22 at 06:31

1 Answers1

0

A premise in your question is incorrect:

I have use git clone {url}, and it only clone the master/main branch.

By default, a clone will include every branch that is in the remote repo. After you clone a repo, you will have a single branch checked out (typically main or master). If you run the command:

git branch

you will only list your local branches. All of the other branches are there on your local clone, and to view all local and remote tracking branches you should use the --all option:

git branch --all

You can switch to (or checkout) any of those branches if you want to work on them. Otherwise you can view their logs to see what interests you.

More info about listing branches is documented here.

TTT
  • 22,611
  • 8
  • 63
  • 69