改变一个Git远程头指向除了主人之外的东西 [英] Change a Git remote HEAD to point to something besides master
问题描述
我如何设置一个Git remote的HEAD引用来指向除master之外的其他东西?
我的项目有一个不使用master分支的策略所有分支机构都要有有意义的名称)。此外,规范主存储库只能通过ssh://访问,无需shell访问(如GitHub或Unfuddle)。
我的问题是远程存储库仍然存在HEAD引用refs / heads / master,但我需要它指向不同的分支。这造成了两个问题:
-
克隆回购时,出现这种情况,
警告:远程HEAD引用不存在的ref,无法结帐。
不方便。
-
基于网页的代码浏览器依赖HEAD作为浏览树的基础。然后,我需要HEAD指向一个有效的分支。
几乎是一年前的 GitHub上的相同问题。 -
HEAD
引用refs / heads / master
并且存在
- >您将获得一个名为master的本地分支, from origin / master -
HEAD参考
refs / heads / master
并且不存在
- >git clone抱怨 When cloning the repo, there this,
warning: remote HEAD refers to nonexistent ref, unable to checkout.
That's confusing and inconvenient.
The web-based code browser depends on HEAD as a basis for browsing the tree. I need HEAD to point to a valid branch, then.
HEAD
referencesrefs/heads/master
and that exists
-> you get a local branch called master, starting from origin/masterHEAD references
refs/heads/anotherBranch
and that exists
-> you get a local branch calledanotherBranch
, starting fromorigin/anotherBranch
HEAD references
refs/heads/master
and that doesn't exist
-> "git clone" complains
这个想法是重命名master分支:
git branch -m master开发
git分支-m已发布master
git push -f原始大师
让主人拥有你想要人们使用的东西,并在分支中做所有其他工作。
(a git-symbolic-ref HEAD refs / head / published
不会传播到远程回购)
这类似于如何删除Git中的origin / master 。
正如这个帖子 :(强调我的)
git clone
只会创建一个本地分支。
要做到这一点,它查看远程仓库的HEAD ref
,并创建一个与它所引用的远程分支名称相同的本地分支。
因此,为了包装它,你有回购A并克隆它:
HEAD引用
开始refs / heads / anotherBranch
并且存在
- >您获取名为anotherBranch的本地分支,从
origin / anotherBranch
不确定是否有任何方法可以直接修改
>HEAD
参考资料库。
(这是你问题的所有观点,我知道;))
也许唯一的方法是为穷人发布,你在哪里:
$ git-symbolic-ref HEAD refs / head / published
$ git-update-server-info
$ rsync - az .git / * server:/local_path_to/git/myRepo.git/
但是,这涉及到对服务器的写入访问权限,这并不总是可能的。
正如我在 Git:在裸仓库中更改Active Branch的正确方法? , git remote set-head
不会改变远程仓库中的任何东西。
它只会改变本地存储在本地仓库中的远程追踪分支,位于 remotes / < name> / HEAD
。
How do I set a Git remote's HEAD reference to point to something besides "master"?
My project has a policy not to use a "master" branch (all branches are to have meaningful names). Furthermore, the canonical master repository is only accessible via ssh://, with no shell access (like GitHub or Unfuddle).
My problem is that the remote repository still has a HEAD reference to refs/heads/master, but I need it to point to a different branch. This is causing two problems:
There was almost the same question on GitHub a year ago.
The idea was to rename the master branch:
git branch -m master development
git branch -m published master
git push -f origin master
Making master have what you want people to use, and do all other work in branches.
(a "git-symbolic-ref HEAD refs/head/published
" would not be propagated to the remote repo)
This is similar to "How do I delete origin/master in Git".
As said in this thread: (emphasis mine)
"
git clone
" creates only a single local branch.
To do that, it looks at theHEAD ref
of the remote repo, and creates a local branch with the same name as the remote branch referenced by it.So to wrap that up, you have repo A and clone it:
Not sure if there's any way to directly modify the
HEAD
ref in a repo.
(which is the all point of your question, I know ;) )
Maybe the only way would be a "publication for the poor", where you:
$ git-symbolic-ref HEAD refs/head/published
$ git-update-server-info
$ rsync -az .git/* server:/local_path_to/git/myRepo.git/
But that would involve write access to the server, which is not always possible.
As I explain in "Git: Correct way to change Active Branch in a bare repository?", git remote set-head
wouldn't change anything on the remote repo.
It would only change the remote tracking branch stored locally in your local repo, in remotes/<name>/HEAD
.
这篇关于改变一个Git远程头指向除了主人之外的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!