markdown 在本地和远程删除Git分支

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 在本地和远程删除Git分支相关的知识,希望对你有一定的参考价值。

# Delete Git branch locally and remotely
I stumble across this one every so often. And since I have to look it up every time, I may as well document it. Today's post is small and easy.

To delete a Git branch after the completion of a feature or bug fix, you can use the following commands. Cause the CLI rules, right, RIGHT?
Anyway, back to the task at hand.
```
## Delete a remote branch
$ git push origin --delete <branch> # Git version 1.7.0 or newer 
$ git push origin :<branch> # Git versions older than 1.7.0

## Delete a local branch
$ git branch --delete <branch>
$ git branch -d <branch> # Shorter version
$ git branch -D <branch> # Force delete un-merged branches

## Delete a local remote-tracking branch
$ git branch --delete --remotes <remote>/<branch>
$ git branch -dr <remote>/<branch> # Shorter
$ git fetch <remote> --prune # Delete multiple obsolete tracking branches
$ git fetch <remote> -p # Shorter
```
As you realize, there are 3 different branches that need to be deleted in Git:

The local <branch>
The remote origin/<branch>.
The local remote-tracking branch origin/<branch> that tracks the remote <branch>
No more googlebinging for this. Now you know where to get the answer :)

以上是关于markdown 在本地和远程删除Git分支的主要内容,如果未能解决你的问题,请参考以下文章

Git 中删除本地分支和删除远程分支是两回事儿

Git 中删除本地分支和删除远程分支是两回事儿

如何在本地和远程删除 Git 分支?

删除本地git的远程分支和远程删除git服务器的分支

git删除本地分支和远程分支

git --- 删除本地分支和远程分支操作