How to close off a Git Branch?

GitGithub

Git Problem Overview


I'm starting out using Git + GitHub.

In our distributed team, each member is creating their own branch for each issue/requirement they are allocated.

  1. git branch Issue#1 <-- create this branch
  2. git checkout issue#1 <-- switch over to this branch

now code code, commit, code, commit, etc...

then pull request, code-fixup, commit, code, commit .. etc.

and finally the pull request is accepted.

But, now what?

Does the person who created the branch on their local dev machine need to close off the branch? A suggestion was for the dev person to delete the branch ( ... -D ...) and then do a pull / refresh of the master .. which then will get all their branch code.

Git Solutions


Solution 1 - Git

We request that the developer asking for the pull request state that they would like the branch deleted. Most of the time this is the case. There are times when a branch is needed (e.g. copying the changes to another release branch).

My fingers have memorized our process:

git checkout <feature-branch>
git pull
git checkout <release-branch>
git pull
git merge --no-ff <feature-branch>
git push
git tag -a branch-<feature-branch> -m "Merge <feature-branch> into <release-branch>"
git push --tags
git branch -d <feature-branch>
git push origin :<feature-branch>

A branch is for work. A tag marks a place in time. By tagging each branch merge we can resurrect a branch if that is needed. The branch tags have been used several times to review changes.

Solution 2 - Git

after complete the code first merge branch to master then delete that branch

git checkout master
git merge <branch-name>
git branch -d <branch-name>

Solution 3 - Git

Yes, just delete the branch by running git push origin :branchname. To fix a new issue later, branch off from master again.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPure.KromeView Question on Stackoverflow
Solution 1 - GitBill DoorView Answer on Stackoverflow
Solution 2 - GitDauView Answer on Stackoverflow
Solution 3 - GitGaurav GuptaView Answer on Stackoverflow