首页 > 解决方案 > 从 git-branch 重新隐藏远程分支

问题描述

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

假设我想重新隐藏remote-branch. 这可能吗?git branchmaster

标签: gitbranch

解决方案


当您这样做时git checkout remote-branch,git 首先尝试在本地查找该 ref。

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

这就是为什么当你这样做时可以看到它列出的原因git branch

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

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>

推荐阅读