tags:

views:

83

answers:

2

I am trying to set up a git server with bunch of repositories. I am planning to use the branching model described in http://nvie.com/git-model article. So I will have at least two branches (named master and develop) in the repository.

After a clone the master branch is checked out by git. Is there a git config option so that develop branch will be checked out instead?

In effect I want git clone my_repo_url to behave as git clone -b develop my_repo_url.

+3  A: 

git clone will:

creates and checks out an initial branch that is forked from the cloned repository's currently active branch.

(i.e. where HEAD refers to in that remote repo)

So if repo is checked-out with develop on the remote server, any clone will check out the develop branch.

But, chances are your remote git repo is a bare repo one (no working tree) in order to allow pull and push.
In this case, you need to make sure that its HEAD refers to develop branch.
If it currently doesn't, clone it, checkout develop branch, push with a trivial addition, and see if any subsequent clones do checkout develop.

That would only prove that the HEAD of a bare repo can be influence by any push on it.
So the true solution would be a pre-receive hook (not an update or commit hook, since it is a bare repo) set on the bare remote repo to ensure that HEAD refers to develop branch if it exists, master otherwise.

Note: this thread mention you cannot in general influence directly the HEAD on the remote repo:

The remote command is about updating things under .git/refs/remotes, not about updating a remote server. For updating a remote server, there is really only push.

On GitHub, a request exists to set the HEAD on a GitHub (bare by definition) repo.

VonC
Thank you very much! I edited HEAD in the bare server repo to point to _develop_ branch. Subsequent commits to other branches didn't move it.
Suraj Barkale
It is a shame that you need to login into the remote server to change HEAD.
Suraj Barkale
@Suraj: interesting: pushing on a `bare` repo won't change its HEAD. Makes sense, somehow. But as you say, that means a *local* setting on the bare repo itself.
VonC
@Suraj: did you test pushing commits from another branch, then cloning your updated bare repo?
VonC
@VonC: Yes I did following:1. Change HEAD file in remote repo to develop branch.2. Clone repo, commit to master branch and push master.3. Clone repo at another location and verify that develop branch gets checked out even though the latest commit is in master branch.
Suraj Barkale
@Suraj: perfect! Although Jakub's answer and comment suggest that might change in the future.
VonC
+1  A: 

git clone currently doesn't have such option, but you can check out other branch after clone, and change where 'origin/HEAD' points to with git remote set-head <remote>.

You can use instead git init + git remote add, which has -m <master> option + git remote update.

Jakub Narębski
But, as mentioned in the thread I point to in my answer (http://lists-archives.org/git/707874-git-remote-set-head-not-working.html), git remote set-head is only a *local* setting. It has no influence on the actual remote repo, right? Concurrently, does the git remote update change anything on the remote repo?
VonC
Currently git cannot set HEAD in remote repository via push (it might change in the future if git transfer protocols acqure capability to transfer symbolic references as symbolic references), and of course read-only wrt remote repository `git fetch` / `git clone` / `git remote update` do not change anything in remote repository.
Jakub Narębski
@Jakub: didn't see your comment right away. It is clearer now. +1
VonC