摆脱分支机构的存储库名称前缀 [英] Getting rid of the repository name prefix from branches

查看:45
本文介绍了摆脱分支机构的存储库名称前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下命令将整个GitHub存储库克隆到本地计算机上:

I cloned my entire GitHub repository to a local computer using:

git clone git@github.com:my_account_name/my_repository_name.git

假设我在远程存储库上的分支是 foo bar .当我这样做时:

Suppose the branches I had on the remote repository were foo and bar. When I do:

git branch -r

本地计算机上存储的远程分支列出了名称:

the remote branches stored on my local computer are listed with the names:

origin/foo
origin/bar

(在 git branch -a 中,它们以 remotes/进一步加前缀.)当我在本地计算机上的分支上工作时,我想引用没有 origin/前缀的分支.对于每个分支,我可能都可以这样做:

(And with git branch -a, they appear with remotes/ further prefixed.) When I work on the branches on my local computer, I want to refer to the branches without the origin/ prefix. For each branch, I can probably do like:

git branch -m origin/foo foo

重命名分支,但是我实际上有很多分支,并且不想一个接一个地手动进行.是否有办法一次消除本地计算机上多个远程分支的这些 origin/(或 remotes/origin/)前缀?

to rename the branch, but I actually have a lot of branches, and do not want to do it manually one by one. Is there a way to get rid of these origin/ (or remotes/origin/) prefix for multiple remote branches on the local computer at once?

推荐答案

只需执行 git checkout foo .就是这样.

您不应重命名或在 origin/* 分支中工作,它们会跟踪远程存储库的状态.您不能直接在其中工作,而是创建本地副本.

You're not supposed to rename or work in the origin/* branches, they track the remote repository's state. You don't work in them directly, you create your local copies.

检出本地不存在但远程存在的分支会自动为您创建此分支,因此只需进行检出,但省略 origin/部分.

Checking out a branch which doesn't exist locally but does exist remotely creates this branch automatically for you, so just do a checkout but omit the origin/ part.

这篇关于摆脱分支机构的存储库名称前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆