Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git clone - default branch

Tags:

git

gitlab

After cloning a git repository from my gitlab server, it does not checkout master, as origin/HEAD points to some other branch 'origin/foo'. In gitlab, the default branch is set to master.

How can I move origin/HEAD from 'origin/foo' to point to 'origin/master', so that further clones automatically check out origin/master?

Right after cloning, git remote show origin states:

HEAD branch: foo

git remote -r seconds that:

origin/HEAD -> origin/foo

I want the HEAD branch to point to master, though - inside gitlab - the default branch is already set to master.

like image 381
rralf Avatar asked Mar 23 '16 23:03

rralf


People also ask

How do you clone a main branch?

In order to clone a specific branch, you have to execute “git branch” with the “-b” and specify the branch you want to clone. $ git clone -b dev https://github.com/username/project.git Cloning into 'project'... remote: Enumerating objects: 813, done.

What is the default branch in git clone?

git clone --single-branch : By default, git clone will create remote tracking branches for all of the branches currently present in the remote which is being cloned. The only local branch that is created is the default branch.

Does git clone take all branches?

While you can clone repositories with the git clone command, keep in mind that this clones the branch and the remote HEAD . This is usually master by default and includes all other branches in the repository. So when you clone a repository, you clone the master and all other branches.


1 Answers

This can be done only server-side. For GitLab, it is done in your project, Settings (last item in the sidebar on the left), "Default Branch" (third text field).

Screenshot of GitLab Project Settings page

Apparently there is an issue at the moment (March 2016) which means that the default branch reported by GitLab is not always the same as the HEAD branch reported by git remote show origin. Setting the GitLab default branch to anything else, then setting it back to master, has worked for @rralf.

like image 64
Paul Hicks Avatar answered Oct 01 '22 18:10

Paul Hicks