Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

default HEAD in git when multiple branch HEADs refer to the same SHA1

Tags:

git

head

in my project, I usually have a (development) branch leading to the next release version at which point the development branch will be merged into the release branch, and then a new development branch will be created.

This means, two branch HEADs will be pointing to the same commit:

$> cd project.git  
$> rgrep release .  
    ./packed-refs:2808f1de3e05bf7fcc509c20f31a93e2ba645bd3 refs/heads/release  
$> rgrep 2808f1de3e05bf7fcc509c20f31a93e2ba645bd3 .  
    ./packed-refs:2808f1de3e05bf7fcc509c20f31a93e2ba645bd3 refs/heads/release  
    ./packed-refs:2808f1de3e05bf7fcc509c20f31a93e2ba645bd3 refs/heads/development_0103  

I want people who clone from my repo to automatically get a check out of the release branch.

$> cd project.git  
$> git symbolic-ref HEAD  
    refs/heads/release  

but, when cloning from that repo apparently people get the alphabetically first matching branch checked out

$> git clone project.git/ project.clone  
$> cd project.clone  
$> git status  
    # On branch development_0103  
    nothing to commit (working directory clean)  

It seems to me git is working out the branch name to check out by looking at the SHA1, but not actually using the remote's symbolic-head HEAD.

Is there any way to solve this and make the clone default to 'release' instead of 'development_0103'?

like image 322
Andre D Avatar asked Feb 28 '11 17:02

Andre D


People also ask

What is the default head in Git?

The term HEAD refers to the current commit you are viewing. By default, you'll view the tip of the master branch on a repository, unless the main branch of your repository has a different name. The tip of the master branch is the most recent commit on the main branch of your codebase.

What is head in Git how many heads you can create in Git?

When working with Git, only one branch can be checked out at a time - and this is what's called the "HEAD" branch. Often, this is also referred to as the "active" or "current" branch. Git makes note of this current branch in a file located inside the Git repository, in .

Can two different branches refer to same commit in Git?

Yes, two branches can point to the same commits.

What does Head @{ 3 refer to?

ref~2 means the commit's first parent's first parent. ref~3 means the commit's first parent's first parent's first parent. And so on. ref^ is shorthand for ref^1 and means the commit's first parent.


1 Answers

You can use separate remote repository for pushing public releases instead of using your way. You will work as usual in your dev remote repo. merge stable commit to the release branch. and after that git push release_origin release. So you could share only this release_origin repo with another people.

Or there is another hack for that. :) Just rename your release branch to a_release, so it will be first alphabetically. :)

like image 158
Evgen Bodunov Avatar answered Sep 21 '22 14:09

Evgen Bodunov