1

When I do git clone ..., then git branch shows the current branch is not master.

Doing git checkout master leaves me where I want. But this is actually what I don't want to do (nor force everyone else to do).

How can I make master the current branch just after I clone the repository? That is, how can I change remote HEAD so that when someone clones the repo it is already on master?

I'm hosting my own repo, access over SSH to another machine in local network.

KcFnMi
  • 5,516
  • 10
  • 62
  • 136
  • Are you cloning from Github? If yes what is the first branch that you see when you go to the repo's page? – TheGeorgeous Sep 10 '15 at 12:21
  • 1
    When you say you don't want to do 'git checkout master', do you mean that you don't want to have to do this as an extra step? – Jeremy Sep 10 '15 at 12:21
  • @Jeremy, you went exactly to it, could you please direct me to the solution? – KcFnMi Sep 10 '15 at 12:48

2 Answers2

1

From the man page displayed by git help clone:

   --branch <name>, -b <name>
       Instead of pointing the newly created HEAD to the branch pointed to by
       the cloned repository’s HEAD, point to <name> branch instead. In a
       non-bare repository, this is the branch that will be checked out.  
       --branch can also take tags and detaches the HEAD at that commit in the
       resulting repository.

So git clone -b master ... should do what you want.

Jeremy
  • 5,055
  • 1
  • 28
  • 44
  • Actually, I would like to go with the default `git clone`. But, in order to allow it to leave me in master, something must be adjusted (corrected). How to perform the adjusment? – KcFnMi Sep 10 '15 at 12:55
  • As the quoted text says, by default (i.e. without an explicit -b option) the HEAD of your local clone will depend entirely on the HEAD of the repo you're cloning. Unless you can control the HEAD of the remote repo, you simply _cannot_ control the outcome for your local clone without using '-b'. – Jeremy Sep 10 '15 at 13:01
  • Yes, I understand. I can control the HEAD of the remote repo (it's mine) but don't know which actions must be performed :(. May I ask your help on this approach? – KcFnMi Sep 10 '15 at 13:21
0

The solution was to "manually change" (edit) the HEAD file on the server, as pointed by @Jefromi at https://stackoverflow.com/a/8841024/5082463.

Community
  • 1
  • 1
KcFnMi
  • 5,516
  • 10
  • 62
  • 136