My environment in local:
git-flow
Steps
feature x
in Sourcetree then I add the code.commit
including the option to create a pull request
and push
the changes to feature x
branch in remote
.pull request
I select the option for Close {branch} after the pull request is merged
.pull request
then merges it into the develop
branch.pull
the new changes to my local develop
branch.NOTE It's important to review the code through pull request
before merging it into develop
, so the question is:
Is there any way to delete automatically the feature x
branch in my local after made a pull
in develop
?
*I tried with a fetch
but it does not work.
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.
One simple, non-automated way to handle this is to periodically run a branch cleaning command in your local repo, like
# to be executed with your "main" stable branch checked out
git branch -d $(git branch --merged)
It'll delete every already merged local branch (i.e. those which do NOT have "not yet merged" commits). So all these branches which have been merged through pull requests will be deleted, but not the few ones that have recent (not reviewed/not merged) commits.
Note : if your policy is to squash commits upon pull request, this won't be a suitable solution, since your local branches still have the original (pre-squash) commits, so they won't be viewed as merged and won't be deleted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With