Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to backup a branch in git and be able to "reimport" it?

Tags:

git

I have a branch I want to delete but possibly be able to restore it with full history -is there a way to do this ? So want this:

a - b - c - d - e    master
     \
      f - g    tmp

to become:

a - b - c - d - e

and have a - b - f - g stored somehow that I can reapply it - is it possible ?

like image 358
Mr_and_Mrs_D Avatar asked Oct 23 '25 18:10

Mr_and_Mrs_D


2 Answers

Perhaps you could use git fast-export to save the branch to a file. Then if you need it later you can use git fast-import to get it back.

To accomplish saving the single branch tmp (that is, commits f and g), you could use the triple dot syntax, as follows:

git fast-export master...tmp
like image 107
M.M Avatar answered Oct 26 '25 08:10

M.M


Just clone the repository to another location and then delete the branch from the original repository. You will be able to examine it in the cone and if needed pull it back in from there.

A branch in a clone is basically nothing more than a branch that lives somewhere distinct from your current repository. You can always move the branch back to your old repository at a later point.

It's even easier to push back the branch to your original repository from your clone.

So, in your clone just do:

git push origin that_branch 

Ever pushed a branch to github? Yep, that's exactly the same thing.

like image 41
Christoph Avatar answered Oct 26 '25 08:10

Christoph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!