Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

what determines default branch when cloning from git bare repository

I'm trying to change the default branch when cloning from a git bare repo using git 1.8.3.1 from yum install. I had always assumed that the way to do this would be to change the reference inside the HEAD file of the remote repo, and several SO answers seem to confirm this.

However, I'm finding the value of HEAD in the remote bare repo to have no effect. Even though my remote repo has this value in HEAD:

ref: refs/heads/secondbranch

I'm still defaulted to firstbranch branch when I clone! Any ideas what's going on here? Where else might this info be stored?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Old versions of git do not send the "default branch" when fetching and cloning. Instead, they send the object ID of the current HEAD reference, as well as the object ID of the other references. If the object ID of HEAD is the same as the object ID of another reference, it will set HEAD to point to that reference. (If there was no match, you will be in a detached HEAD state.)

The disambiguation logic is fuzzy, though, if you have more than one branch pointing to the same commit. It will prefer a branch named master, then it will simply pick the one it saw first.

Stop laughing, I'm serious.

This was fixed in Git 1.8.4.3.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...