0

I searched for this answer and could not find it.

I am not looking to create a new branch, I found that one of my branches has legacy code in it, I am going to be destroying that branch and creating a new similar one with our upgraded project, but I would like to just save a copy of this legacy branch anywhere on my machine.

What's the best way to do this via command line?

halfer
  • 19,824
  • 17
  • 99
  • 186
Daniel
  • 14,004
  • 16
  • 96
  • 156
  • 2
    Don't do anything and just abandon the branch? – mkrieger1 Nov 14 '19 at 15:33
  • 2
    Possible duplicate of [How can I archive git branches?](https://stackoverflow.com/questions/1307114/how-can-i-archive-git-branches) – mkrieger1 Nov 14 '19 at 15:34
  • @mkrieger1, I think that would confuse things, because I will be making a new updated branch of the same name. It's hard for me to say whether I just asked a duplicate question to the one you brought up. When git archiving, can I pull the code up of this archive often? For me archive seems more like something I will not look at again and I do plan to look at this branch often. This is why I did not find the possible duplicate because I am not thinking of it as an archive, but just something to reference back to often. – Daniel Nov 14 '19 at 16:15
  • 1
    If you plan to look at it often but want to reuse the branch name for something else, then the simplest solution would be to just rename the existing branch. – mkrieger1 Nov 14 '19 at 16:46
  • @mkrieger1, hmm, that sounds like what I need and the how-to for that is here: https://stackoverflow.com/questions/6591213/how-do-i-rename-a-local-git-branch – Daniel Nov 14 '19 at 16:54

2 Answers2

2

You could just set up another branch in your local repo and save it forever... but another way using git is to put it in another repo. So say your repo is in directory one.... I will set up another repo called two for it:

git init two
cd one
git remote add another-repo local-path-to-two
git push another-repo my-branch

Now, if you go to two, you will see the whole branch as it was.

cd ../two
git checkout my-branch
git log
eftshift0
  • 26,375
  • 3
  • 36
  • 60
0

A branch is an archive — the branch name preserves the work forever — so there is nothing to do. If I don’t want to see this branch in my list of branches, what I do is reset the branch (so that it is turned into uncommitted code in the worktree) and stash it with a name. Again, the name preserves the work. You lose your commit history but the code is now archived and can be examined at any time.

matt
  • 515,959
  • 87
  • 875
  • 1,141