Arif Nadeem
Arif Nadeem

Reputation: 8604

Using Gitlab's API, how can I switch between branches?

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?

Upvotes: 2

Views: 2515

Answers (1)

VonC
VonC

Reputation: 1323953

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.

Upvotes: 3

Related Questions