0

I am working on a project with my team, we use master as our stable branch, and dev for new features that have been implemented but are being tested before we merge the changes into master. I created a branch from dev called new-feature-1, and made several commits on this branch, making sure to push these changes to our remote along the way. I have now completed my work on new-feature-1 and I merge it with to dev, it gets accepted and merged with master. The feature has been implemented and I no longer have need for new-feature-1 as a branch, but it's on both my local machine, and more importantly the remote.

What is usually done in a scenario like this? Do I delete new-feature-1 and force push the deletion to remote? Or is it standard practice to leave it there? What do most people/companies do in this scenario?

Jhon Piper
  • 513
  • 2
  • 8
  • 21
  • 1
    Does this answer your question? [What to do with branch after merge](https://stackoverflow.com/questions/14005854/what-to-do-with-branch-after-merge) – krisz Apr 09 '20 at 15:13

3 Answers3

2

Keep in mind that a branch is nothing but a snippet of text, commonly known as a name. That is all your branch ever was. The reason you need a branch is because a commit that neither has a name nor is the parent (at some depth) of a commit with a name, is unreachable and will eventually die. So if you

  • Do not need to reach the commits on this branch, or

  • Can reach all the commits on this branch that you need to, because the branch was merged into another branch

then the name serves no purpose and should be deleted, as it merely clutters up the namespace.

[Alternate metaphor:] Think of a branch as a bookmark. It holds your place while you work. When you're done working, you don't need the bookmark any more; there is no place to hold.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • May I suggest "and will eventually be garbage-collected (after a month or so)" rather than "will die"? – jthill Apr 09 '20 at 02:26
2

I would recommend not to delete it right away. You don't know what the client wants and you might need it for some reason. We all know there's still a final requirement update after every final.

You can always delete, but you can not get back the branch. Though you will have all the commits from that branch after you merge it, having the branch might make your jobs easier.

My suggestion is to keep the branch for some time. Then once you see you are not using it then delete it.

omar jayed
  • 850
  • 5
  • 16
1

If no one is going to use the branch any more, you should delete it with git branch delete branchname. You can delete it on the remove server with git push -d origin branchname. (There is no need for force)

Since the branch has been merged, there is no fear of loss in deleting the branch, since the branch can easily be re-created at any time in the future using git branch branchname commitid where the commitid is gotten from git log --graph --oneline --decorate --all

JoelFan
  • 37,465
  • 35
  • 132
  • 205