如何停止跟踪Git中的远程分支?

我要求停止跟踪,因为在我的具体情况下,我想删除本地分支,但不是远程分支。删除本地分支并将删除推到remote也会删除远程分支:

如何在本地和GitHub中删除Git分支?

我能不能只做git branch -d the_branch,当我之后推送git时,它不会被传播?

如果我稍后运行git push origin:the_branch,它是否只会传播?


当前回答

最简单的方法是远程删除分支,然后使用:

Git获取——删除(也就是Git获取-p)

其他回答

Git分支——unset-upstream停止跟踪所有本地分支,这是不可取的。

从.git/config文件中删除[branch "branch-name"]段

git branch -D 'branch-name' && git branch -D -r 'origin/branch-name'

这对我来说是最好的。

您可以使用这种方式删除远程分支

git remote remove <your remote branch name>

最简单的方法是远程删除分支,然后使用:

Git获取——删除(也就是Git获取-p)

删除本地分支和远程分支之间的关联:

git config --unset branch.<local-branch-name>.remote
git config --unset branch.<local-branch-name>.merge

如果你不需要,可以选择删除本地分支:

git branch -d <branch>

这不会删除远程分支。

下面是删除所有与模式匹配的远程跟踪分支的一行代码:

Git branch -rd $(Git branch -a | grep '{pattern}' | cut -d'/' -f2-10 | xargs)