2

I want to switch from my master branch to my development branch using Gitlab's API, I've researched all the documented API's available here, but there isn't such an API.

Has someone tried this before as this is a very common scenario?

Is it possible to do the same via the API?

Arif Nadeem
  • 8,524
  • 7
  • 47
  • 78

1 Answers1

3

Switch between branches?

On the GitLab server side (which is what the Gitlab API refers to), you don't switch branches, since GitLab is managing bare repos (repos without a working tree, with any branch checked out).

You might mean: "How to change the default branch" (the one checked out by default when a user clone a remote repo managed by GitLab).

That is possible with gitolite (see "git change default branch (gitolite)").
However, it isn't with GitLab: the relevant API would be "Projects", but the "branch" section doesn't include anything to change the symbolic ref of HEAD of a bare repo managed by GitLab.

That means you have to go on the server itself, within the bare repo, in order to execute a:

git-symbolic-ref HEAD refs/head/development 

onionjake mentions in the comments:

If you are using the omnibus packages you might not have git installed in the usual spot.
I had to do:

/opt/gitlab/embedded/bin/git symbolic-ref HEAD refs/heads/development.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I wanted to switch branches(or more appropriately change my default branch)because I wanted to get repository tree for different branches(for master, development etc), if you see Gitlab's web interface, when you click on files tab, you can select the branch in a dropdown list, the repository tree changes. How do they do it? Is there some way I could do it using the existing API? I am open to write a new API for that but it would be better if I could just use an existing one. – Arif Nadeem Jun 27 '13 at 11:31
  • I got it thank you very much once again, I just had to send a ref_name parameter as branch name to list repository tree API. – Arif Nadeem Jun 27 '13 at 11:43
  • @ArifNadeem yes, listing the repo tree is supported. – VonC Jun 27 '13 at 12:06
  • If you are using the omnibus packages you might not have git installed in the usual spot. I had to do `/opt/gitlab/embedded/bin/git symbolic-ref HEAD refs/heads/development`. – onionjake Jul 22 '14 at 21:44
  • @onionjake good point. I have included it in the answer for more visibility. – VonC Jul 23 '14 at 05:35