简体   繁体   English

当使用git删除相应的本地分支时,如何自动删除远程跟踪分支

[英]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.

相关问题 如何创建git Remote-Tracking分支 - How to create git Remote-Tracking Branch 它们的名称是否相同:本地跟踪分支,相应的远程跟踪分支以及正在跟踪的相应远程分支? - Are their names the same: a local-tracking branch, the corresponding remote-tracking branch, and the corresponding remote branch being tracked? Git:如何获取单个远程分支并自动创建远程跟踪分支? - Git: How to fetch a single remote branch and create a remote-tracking branch of it automatically? 通过一个Git远程跟踪分支的名字如何找到本地分支跟踪它? - By given name of a Git remote-tracking branch how to find which local branch tracks it? 删除远程分支时如何删除本地远程跟踪分支? - How do I delete local remote-tracking branches when remote branch is deleted? 当远程分支被删除时,本地 git 分支是否会自动删除? - Are local git branches ever deleted automatically when their remote branch is removed? Git - 推送到远程存储库中的远程跟踪分支 - Git - push to a remote-tracking branch in the remote repository Git:如何在不提取的情况下自动将本地分支与远程跟踪合并 - Git: How to merge local branch with remote tracking automatically without fetching GIT:删除没有本地跟踪分支的远程分支 - GIT: remove remote branches with no local tracking branch 如何在Git中不预先合并远程跟踪提交的情况下创建新分支? - How to create a new branch without pre-merge remote-tracking commits in Git?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM