Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide but still save a branch with GIT?

Tags:

git

I have a large number of branches which is getting a bit confusing to work with. Sometimes I dont want to delete the branch completely but I wont be working on it for a while. Ive adopted a convention of prefixing branches with _ when that is the case.

So if i start out with:

branch1
branch2
branch3

When Im done with branch1 but want to save a backup of it just incase then ill rename to:

_branch1
branch2
branch3

This worked well for a while but my workspace is getting a bit cluttered now. Is there anyway of saving a branch somewhere so it can be recovered, but so that its not in the normal workspace (as if its been deleted)?

like image 313
Evanss Avatar asked Oct 19 '22 15:10

Evanss


1 Answers

You can use tags for many of the same sorts of things as branches:

git tag saved_branch1 branch1
git branch -D branch1

And, to recover the branch:

git branch branch1 saved_branch1
git checkout branch1

The catch is that tags can accidentally get pushed upstream, so you have to be careful to avoid that:

git push --tags         ;# Don't do this!
git push --follow-tags  ;# This will only push annotated tags on some commits

Since the tag command I showed above does not create annotated tags (it creates lightweight tags) those will not be pushed.

like image 154
ams Avatar answered Oct 31 '22 14:10

ams