9

What is the best way to backup a complete branch from a local git repository on one PC with the purpose of adding it to a local git repository on another PC.

In the case where the remote git repository server is offline due to failures on their end.

Knossos
  • 15,802
  • 10
  • 54
  • 91

2 Answers2

7

First, you can make a local clone of your current repo, including only your branch:

git clone -b mybranch --single-branch /path/to/your/local/repo.git

Then you can make a bundle of that repo, in order to easily save it (a bundle is a Git repo, compressed into one file).

If you have the possibility to make a bare empty repo somewhere accessible (even through a simple shared folder), you could simply push your branch to it.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • OK, this is looking promising. I am in the process of cloning. Bundle sounds like exactly what I need. – Knossos Nov 19 '14 at 09:03
  • @Knossos if you don't have the possibility to make an empty bare repo in a location acting as backup, bundle is indeed the next best option. – VonC Nov 19 '14 at 09:04
  • I should probably have added to the question - I am accessing the other PC by remote desktop software. In order to make this back up. It is not in the same area as I am. So a single file to transmit over the internet seems ideal to me. – Knossos Nov 19 '14 at 09:22
  • That did it. I could transfer the bundle, add it as a remote to my local repository and everything went like a knife through butter. – Knossos Nov 19 '14 at 09:44
3

as oneliner for per minute backup ... ( this will bloat your git branch -a )

 git branch $(git rev-parse --abbrev-ref HEAD)--$(date "+%Y%m%d_%H%M") && git branch -a | grep -i $(git rev-parse --abbrev-ref HEAD)

which is actually a 2 liner:

git branch $(git rev-parse --abbrev-ref HEAD)--$(date "+%Y%m%d_%H%M");
git branch -a | grep -i $(git rev-parse --abbrev-ref HEAD)
Yordan Georgiev
  • 5,114
  • 1
  • 56
  • 53