[英]How to automatically remove remote-tracking branch when the corresponding local branch is removed using git
The current setup: 当前设置:
$ git branch -a
* master
feature
remotes/origin/master
remotes/origin/feature
After feature
branch is merged, I would like to remove local branch feature
and remote-tracking branch origin/feature
. 合并feature
分支后,我想删除本地分支feature
和远程跟踪分支的origin/feature
。 The remote branch on server is already removed in this case. 在这种情况下,服务器上的远程分支已被删除。
The commands I need is: 我需要的命令是:
$ git branch -d features
$ git branch -d -r origin/features
Is there a way that the second command is automatically triggered when the corresponding local branch is removed? 有没有一种方法可以在删除相应的本地分支后自动触发第二个命令? Any git-config
settings? 任何git-config
设置?
If you set git config fetch.prune true
, then the second command can be a simple git fetch
. 如果将git config fetch.prune true
设置git config fetch.prune true
,则第二个命令可以是简单的git fetch
。
That will prune any remote tracking branch origin/feature
, since feature
was already deleted on the server side. 这将修剪所有远程跟踪分支的origin/feature
,因为该feature
已在服务器端删除。
Even if you don't use the config setting, a git fetch --prune
would do the same. 即使您不使用config设置, git fetch --prune
也会做同样的事情。
In both cases, the advantage is that it will prune any remote tracking branch already deleted on the server (instead of just one branch). 在这两种情况下,优点是它将修剪服务器上已经删除的任何远程跟踪分支(而不只是一个分支)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.