Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should we remove a remote Git branch after merging to master?

I would like to know if it's better to delete your branch after merging to master or if we should continue to work on the same separate branch during all the project.

i.e If we are 3 members in the group, each of us create his own branch and works on it during the duration of the project. We all commit in the master branch and pull before we start working on something else. In that way, we know who's working on which branch and we don't get confuse.

Thanks.

like image 965
LuVu Avatar asked Apr 10 '19 15:04

LuVu


2 Answers

So there are tons of literature about how to manage your branches but really I think it comes down to how you want to manage things within your own project. That being said, here is a link for branch workflow from Atlassian that could give a decent opinion:

https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow

Now, all that long article being said, if it makes sense for you all to commit straight to master, I don't think there is anything wrong with that. I personally commit to master for a couple small projects I work on but generally, this is the flow I follow:

  1. Create the master branch for the project
  2. Decide on a feature you want to work on, we'll call it Widget X.
  3. Create a feature branch for that, call it feature-widget-x.
  4. All the developers working on this feature should make their own branches based on what they are working on. For example, if I was working on error handling, I would branch off of feature-widget-x and make a branch called michael-error-handling.
  5. Merge everything into the feature branch and branch off from there as needed to complete the feature.
  6. When the feature is done, merge the feature branch back into the master branch.
  7. Tag and archive the feature branch so you can roll back if needed at any point.
  8. Clean up local developer branches.
  9. Create a new feature branch from master for Widget Y.
  10. Start the whole process again.

I want to note that this is strictly how I do things and has been successful for me in companies where it has been implemented. It may or may not be the best solution for your group of three members though but that is for you to decide. If you do go with this plan, it has the benefit of being able to roll back to a feature as needed and the only branches that persist are the feature branches and the master branch. Much easier than looking through commit logs on a single branch to figure out when you should roll back to if a commit breaks something.

Hopefully this helps. Here are a couple more links below for extra reading:

https://git-scm.com/docs/git-archive

https://git-scm.com/book/en/v2/Git-Basics-Tagging

How can I archive git branches?

like image 85
Michael Platt Avatar answered Sep 24 '22 06:09

Michael Platt


The correct answer to your question is: it depends what you want to do. There is no problem with continue working on the branch that you merged with master. You can also simply delete it if you don't need it ! However, in the setting you describe, I totally agree with the fact that if you work on different parts of the project, then it may be safe to create different branches and keep the master branch as clean and updated as possible for the group.

like image 34
dallonsi Avatar answered Sep 22 '22 06:09

dallonsi