3

I'm thinking about unused branched.

When I create new module I create new branch and name it with pattern "[task_id]-[shortDescription]" - for example: "4389-surveys". When I finish work on this branch I merge it to master and the branch lies unused.

Should I delete this branches or keep it for eventuality? Which practice is better and recommended?

Kai
  • 5,850
  • 13
  • 43
  • 63
Kamil P
  • 782
  • 1
  • 12
  • 29
  • 1
    I can't see the point of keeping unused development branches around. They just add mess to your repository. A number of existing branches won't slow down `git` noticeably but they take some space and make output of `git branch` hard to read. Anyway, if changes have been merged to a public branch they shouldn't be amended but a new commit should be added so it doesn't make sense to keep old changes. – Arkadiusz Drabczyk Oct 28 '15 at 12:09
  • after merging it to master/main you can delete it. One reason that can be considered to keep it is if you like to keep track of the branch's history (e.g. who did what) – Kai Oct 28 '15 at 12:10

1 Answers1

3

Credit @masonk https://stackoverflow.com/a/3392942/ :

Delete after merge is the usual way. This is why git branch -d checks to make sure that the branch is fully merged before it will delete.

There are a few reasons that I can think of to keep a branch around: you might want to hold onto it in case you have bugs coming back once it hits production, or you might want a historical record.

In either case, you have the option of tagging the head of the branch before you delete it. A tag is like a branch in that it is a pointer to a commit, except for a few minor differences:

  1. porcelain usually doesn't display tags in exploratory commands like git show-branch or tab-auto complete in checkout

  2. checking one out doesn't set HEAD (you will be in a detached HEAD)

  3. you can leave a "tag" note on top of the note on the commit that it points at.

This way you preserve history, and if you ever do need to bug fix, I recommend just creating a new branch off of master for the fix.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
love
  • 1,000
  • 2
  • 16
  • 35