从 git-branch 重新隐藏远程分支

Re-hide remote branch from git-branch

我用 git clone 克隆了一个远程仓库。回购有很多分支。在我的本地终端中,我输入 git branch,它显示 master。如果我输入 git branch -a,我会看到本地和远程的所有分支。如果我使用 git checkout remote-branch 切换到远程分支并继续键入 git branch,我将同时看到 masterremote-branch。我在 remote-branch 上工作,一些代码功能无法解决,我决定回到 master git checkout master 并且我不想删除这个 remote-branch.

假设我想从 git branch 重新隐藏 remote-branch,就像我在回到 master 后克隆 repo 时一样。这可能吗?

当您执行 git checkout remote-branch 时,git 首先尝试在本地中找到该 ref。

因为您只有 master(并且假设您是 运行 足够新的 git 版本),它会检查是否有一个具有该名称的远程分支。如果是这样,它会创建一个同名的本地分支,并将上游设置为远程分支。

这就是为什么您可以在执行 git branch

时看到它列出的原因

要"hide"它,您必须将其删除。 (请记住,远程分支不受此影响。)

git checkout master
git branch -d <branchName>

# the above will fail with a message if the branch is unmerged
# (has commits which aren't merged into `master`)
# if you do want the deletion to occur nonetheless, insist with
git branch -D <branchName>