Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do you do with your branch after a pull request on GitHub?

My team is experimenting with using GitHub pull requests for code reviews. My only question is what do you do with the branch after you're done? I would think you'd want to delete the branch, but since GitHub hides branches that have been merged into your current branch, it seemed like maybe I should keep it.

Just curious on what your thoughts on best practices for this are.

like image 646
Randall Avatar asked Oct 26 '11 14:10

Randall


People also ask

What should I do with branch after pull request?

At the bottom of the Pull Request page on Github, below any comments, there will be a button giving you the option to delete the branch. Push it! (Don't worry, you can un-delete - or “restore” - the branch later if you need to.)

What do you do when you get a pull request?

Pull requests let you tell others about changes you've pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before your changes are merged into the base branch.

Does closing a pull request delete the branch?

Deleting a branch used for a pull requestYou can delete a branch that is associated with a pull request if the pull request has been merged or closed and there are no other open pull requests referencing the branch.

What happens when I create a pull request in GitHub?

After you create a branch and make changes to files in a project, you can create a pull request. With a pull request, you can propose, discuss, and iterate on changes before you merge the changes into the project. You can create a pull request in your project's repository with GitHub Desktop.


3 Answers

The rule of thumb that we use (which is here some where on Stack Overflow) is "branches are for work, tags are for history".

Whenever a branch is merged (most likely into master) we tag the merge point using the name of the branch with the prefix "branch" (e.g. branch-topic). Then delete the branch. If we need to resurrect work at the branch point we have the tag to be able to do that.

There are of course exceptions. We have long running branches that we use for various kinds of continuing work. But in general, topic branches are deleted after merging.

On that note, those merges are always done with

merge --no-ff <branch>

This ensures that there is a merge point and a record of the merge occurring.

like image 194
Bill Door Avatar answered Oct 08 '22 06:10

Bill Door


Note that since April, 10th 2013, "Redesigned merge button", the branch is deleted for you:

new merge button

Deleting branches after you merge has also been simplified.
Instead of confirming the delete with an extra step, we immediately remove the branch when you delete it and provide a convenient link to restore the branch in the event you need it again.

That confirms the best practice of deleting the branch after merging a pull request.

like image 41
VonC Avatar answered Oct 08 '22 07:10

VonC


I always delete branches that have been merged into master. A Git branch, after all, is a pointer to a commit, and that commit is now available in the history of another branch, so I don't need the branch anymore. (You can always recreate the branch by looking at the parents of the merge commit.)

like image 16
Fred Foo Avatar answered Oct 08 '22 08:10

Fred Foo