IT박스

마스터 이외의 것을 가리 키도록 Git 원격 HEAD 변경

itboxs 2020. 7. 17. 21:10
반응형

마스터 이외의 것을 가리 키도록 Git 원격 HEAD 변경


"마스터"이외의 것을 가리 키도록 Git 리모컨의 HEAD 참조를 어떻게 설정합니까?

내 프로젝트에는 "마스터"분기를 사용하지 않는 정책이 있습니다 (모든 분기에는 의미있는 이름이 있어야 함). 또한 표준 마스터 리포지토리는 쉘 액세스 권한이없는 ssh : //를 통해서만 액세스 할 수 있습니다 (GitHub 또는 Unfuddle 등).

내 문제는 원격 저장소에 여전히 refs / heads / master에 대한 HEAD 참조가 있지만 다른 지점을 가리켜 야한다는 것입니다. 이로 인해 두 가지 문제가 발생합니다.

  1. 리포지토리를 복제 할 때

    경고 : 원격 HEAD는 존재하지 않는 참조를 나타내며 체크 아웃 할 수 없습니다.

    혼란스럽고 불편합니다.

  2. 웹 기반 코드 브라우저는 트리 탐색을위한 기초로 HEAD를 사용합니다. 유효한 분기를 가리 키려면 HEAD가 필요합니다.


1 년 전 GitHub 에서 거의 같은 질문 이있었습니다 .

아이디어는 마스터 브랜치의 이름을 바꾸는 것이 었습니다.

git branch -m master development
git branch -m published master
git push -f origin master 

주인은 사람들이 사용하기를 원하는 것을 가지게되며, 다른 모든 일을 지부에서 수행합니다.

( " git-symbolic-ref HEAD refs/head/published"은 (는 ) 원격 저장소로 전파되지 않습니다)

이것은 " Git에서 원산지 / 마스터를 삭제하는 방법 "과 유사합니다 .


이 실 에서 말했듯 : (강조 광산)

" git clone"는 단일 로컬 브랜치를 만듭니다.
이를 위해 HEAD ref원격 리포지토리를보고 참조하는 원격 분기와 이름이 같은 로컬 분기를 만듭니다.

그래서 그것을 마무리하기 위해, 당신은 repo A를 가지고 그것을 복제합니다 :

  • HEAD참조 refs/heads/master및 존재
    -> 출발지 / 마스터에서 시작하여 master라는 로컬 지점을 얻습니다.

  • HEAD 참조 refs/heads/anotherBranch및 존재
    -> anotherBranch에서 시작 하는 로컬 브랜치를 얻습니다.origin/anotherBranch

  • HEAD 참조 refs/heads/master및 존재하지 않는
    -> "git clone"불평

HEADrepo 에서 ref 를 직접 수정하는 방법이 있는지 확실하지 않습니다 .

(이것은 당신의 질문의 요점입니다.)


어쩌면 유일한 방법은 "가난한 사람들을위한 출판물" 일 것입니다.

 $ 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.


업데이트 : 리포지토리의 로컬 복사본 ( "클라이언트")에서만 작동합니다. 아래에서 다른 사람의 의견을 참조하십시오.

최신 버전의 git (2014 년 2 월)에서 올바른 절차는 다음과 같습니다.

git remote set-head $REMOTE_NAME $BRANCH

예를 들어, 원격 origin에서 분기로 헤드를 전환하면 develop다음과 같습니다.

git remote set-head origin develop


GitHub에 대해 언급 했으므로 사이트에서 수행하려면 프로젝트로 이동하면됩니다.

admin > Default Branch > (choose something)

끝난.


참조 : http://www.kernel.org/pub/software/scm/git/docs/git-symbolic-ref.html

이것은 git 저장소에서 기본 분기를 설정합니다. 베어 또는 미러 리포지토리에서이를 실행할 수 있습니다.

용법:

$ git symbolic-ref HEAD refs/heads/<branch name>

(일반적으로 동일한 응답이 " 원격 저장소에 git symbolic ref를 작성하십시오 "라는 질문이 있었으며 , 보편적 인 답변을 얻지 못했습니다.

그러나 다양한 git "farms"에 대한 특정 답변이 있습니다 (여러 사용자가 제한된 인터페이스를 통해 git repos를 관리 할 수 ​​있습니다 : http 및 ssh를 통해) : http://Github.com , http://Gitorious.org , http : / /repo.or.cz , Girar ( http://git.altlinux.org ).

이 특정 답변은이 페이지를 읽고 이러한 특정 서비스에 대해 생각하는 사람들에게 유용 할 수 있습니다.


If you have access to the remote repo from a shell, just go into the .git (or the main dir if its a bare repo) and change the HEAD file to point to the correct head. For example, by default it always contains 'refs: refs/heads/master', but if you need foo to be the HEAD instead, just edit the HEAD file and change the contents to 'refs: refs/heads/foo'.


You can create a detached master branch using only porcelain Git commands:

git init
touch GO_AWAY
git add GO_AWAY
git commit -m "GO AWAY - this branch is detached from reality"

That gives us a master branch with a rude message (you may want to be more polite). Now we create our "real" branch (let's call it trunk in honour of SVN) and divorce it from master:

git checkout -b trunk
git rm GO_AWAY
git commit --amend --allow-empty -m "initial commit on detached trunk"

Hey, presto! gitk --all will show master and trunk with no link between them.

The "magic" here is that --amend causes git commit to create a new commit with the same parent as the current HEAD, then make HEAD point to it. But the current HEAD doesn't have a parent as it's the initial commit in the repository, so the new HEAD doesn't get one either, making them detached from each other.

The old HEAD commit doesn't get deleted by git-gc because refs/heads/master still points to it.

The --allow-empty flag is only needed because we're committing an empty tree. If there were some git add's after the git rm then it wouldn't be necessary.

In truth, you can create a detached branch at any time by branching the initial commit in the repository, deleting its tree, adding your detached tree, then doing git commit --amend.

I know this doesn't answer the question of how to modify the default branch on the remote repository, but it gives a clean answer on how to create a detached branch.


First, create the new branch you would like to set as your default, for example:

$>git branch main

Next, push that branch to the origin:

$>git push origin main

Now when you login to your GitHub account, you can go to your repository and choose Settings>Default Branch and choose "main."

Then, if you so choose, you can delete the master branch:

$>git push origin :master


For gitolite people, gitolite supports a command called -- wait for it -- symbolic-ref. It allows you to run that command remotely if you have W (write) permission to the repo.


Related to the question, I ended up here when searching for:

How do I make a local repo aware of a changed default branch on GitHub

For completeness, adding the answer:

git remote set-head origin -a

Simple just log into your GitHub account and on the far right side in the navigation menu choose Settings, in the Settings Tab choose Default Branch and return back to main page of your repository that did the trick for me.

참고URL : https://stackoverflow.com/questions/1485578/change-a-git-remote-head-to-point-to-something-besides-master

반응형