Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: saving old branches

Tags:

git

git-branch

Our team has recently moved to Git. I've been burned a couple times because my cod somehow ended up not being in the develop branch like I wanted it to be. Since then I have stopped deleting the branches I make every day to work on code, in case I need those branches later.

I now have many branches that I don't want to look at in SourceTree every day. However, I still want to save those branches just in case. Is there any way I can save my old branches but keep them aside so as not to pollute my Git repository?

like image 254
Joe Avatar asked Oct 21 '13 13:10

Joe


People also ask

Should you keep old branches?

They're unnecessary. In most cases, branches, especially branches that were related to a pull request that has since been accepted, serve no purpose.

What do I do with old branches in git?

The easiest way to delete local Git branches is to use the “git branch” command with the “-d” option. The “-d” option stands for “–delete” and it can be used whenever the branch you want to clean up is completely merged with your upstream branch. $ git branch -d release Deleted branch feature (was bd6903f).

How can I archive git branches?

Well, there is no such option like archiving branches in git. But we can create a tag with a prefix like “archive”. In other words, we move entry about the feature from branch list to tags list. To restore the branch, checkout it by the tag.

Should you delete branches after merging?

When you're done with a branch and it has been merged into master, delete it. A new branch can be made off of the most recent commit on the master branch. Also, while it is ok to hang onto branches after you've merged them into the master they will begin to pile up.


1 Answers

Branches are there if you want to keep developing and evolving that branch. If that is not the case and you only keep the branches as 'bookmarks', you should use tags instead (and delete the branches).

That way, git branch -a will look cleaner. And if someday you want to go back and see how that branch looked like, you can always checkout the tag, and eventually recreate a branch based on that tag.

like image 62
FedeCz Avatar answered Oct 05 '22 06:10

FedeCz