如果我已将Git分支合并到master,我可以删除分支本身吗?

时间:2014-05-02 20:17:49

标签: git version-control

如果我已将feature branch合并到主分支中并且永远不再需要作为单独的分支,我可以从本地仓库和原始仓库中删除功能分支吗?

3 个答案:

答案 0 :(得分:1)

删除本地git分支:

git branch -D <branch_name>

删除远程git分支:

git push origin --delete <branch_name>

如果问题是它是否会成为问题:不,如果所有提交都已合并。

答案 1 :(得分:1)

是。您可以删除单个功能分支:

# Delete a single branch that has already been completed locally and then remotely

$ git branch -D my-feature-branch
$ git push origin :my-feature-branch

或者,您可以删除已合并到集成分支的所有功能分支:

# The following command deletes all LOCAL branches that have been merged into the current commit, where the branch name starts with 'feature', except for branch 'integration'.
# You will need to remove the 'echo' to actually run it.

$ git branch --merged | grep -i feature | grep -v integration | xargs -i echo git branch -D {}

# The following command deletes all REMOTE branches that have been merged into the current commit, where the branch name starts with 'feature', except for branch 'integration'.
# You will need to remove the 'echo' to actually run it.

$ git branch -r --merged | grep -i feature | grep -v integration | cut -d '/' -f 2 | xargs -n 1 echo git push --delete origin

# The following command deletes all REMOTE branches that have been merged into master
# You will need to remove the 'echo' to actually run it.

$ git checkout master
$ git merge origin/master --ff-only
$ git branch -r --merged | grep -v master | cut -d '/' -f 2 | xargs -n 1 echo git push --delete origin

答案 2 :(得分:0)

如果您认为已合并分支,则使用git branch -d <branchName>git branch --delete <branchName>进行删除是完全安全的,因为它们不会删除尚未合并的分支。如果分支没有合并分支,小写d将导致git警告您,但如果您想删除分支而不保留最新的提交,则git branch -D将强制删除。 / p>

要删除远程分支,请使用git push origin :<branchName>git push origin --delete <branchName>

相关问题