9

How to backup git server? When git server is broken, How can I push my local repository to a new git server?

Jackson
  • 101
  • 1
  • 1
  • 2

2 Answers2

12

You can use:

git bundle

That way:

  • you have only one file to move to a backup server
  • you actually can use this file as an "origin" repo from which you can pull/push data like a regular Git repo.

You will for the first backup create a full bundle:

$ git bundle create /tmp/foo-all --all
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    I think neither cloning, bundling or any other git command will get everything (for example the server side hooks). If you want to be sure to get everything a normal file based copy of the server repository directory would be needed. – Zitrax Jun 13 '16 at 08:51
  • @Zitrax I agree. hooks are not meant to be gotten or backed up within the same git archive, because they can be local to where the repo is used. I would back them up separately. But if those hooks are not an issue, a tar of the all repo would be enough indeed. – VonC Jun 13 '16 at 09:19
2

You back it up like any other server, just mirror the files; git stores its metadata in files like anything else. If you move the repository to a new machine, you need to change your local repository's origin to point to it. In .git/config you'll find something like:

[remote "origin"]
url = SOMETHING

Change SOMETHING to the address of your new server

Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175
  • thanks a lot! and How to set my backup files become a new git server and keep the git log before? – Jackson May 20 '10 at 03:04