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

标签 git branch git-track

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

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

我可以只执行 git branch -d the_branch,而当我稍后 git push 时它不会传播吗?

它只会在我稍后运行 git push origin :the_branch 时传播吗?

最佳答案

Yoshua Wuyts 中所述' answer , 使用 git branch :

git branch --unset-upstream

其他选项:

您不必删除本地分支。

只需删除正在跟踪远程分支的本地分支:

git branch -d -r origin/<remote branch name>

-r, --remotes告诉 git 删除远程跟踪分支(即删除分支集以跟踪远程分支)。这will not delete the branch on the remote repo !

参见“Having a hard time understanding git-fetch

there's no such concept of local tracking branches, only remote tracking branches.
So origin/master is a remote tracking branch for master in the origin repo

Dobes Vandermeer 中所述的 answer ,您还需要重置与本地 分支关联的配置:

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

Remove the upstream information for <branchname>.
If no branch is specified it defaults to the current branch.

(git 1.8+,2012 年 10 月,commit b84869e Carlos Martín Nieto ( carlosmn ) )

这将使任何推/pull 完全不知道 origin/<remote branch name> .

关于git - 你如何停止跟踪 Git 中的远程分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3046436/

相关文章:

git - 如何创建一个 git 分支,以便我添加到它的文件不会添加到 master?

android - Gradle 脚本自动版本并在 Android 中包含提交哈希

git - 为什么 `git pull` 工作得很好,但 `git push` 却不行?

json - 使用 git 过滤器忽略 json 文件中的特定行

security - TFS仅向一个分支授予权限

git - 不小心创建了一个名为--track的分支,现在我无法删除它

git diff::overriding .gitconfig 外部工具

git - 使用 GIT 分支/分支

branch - 修复 GitLab 错误 : "you are not allowed to push code to protected branches on this project"?

git - 如何删除名为 "--track"的 git 分支