How to pull custom branch to another branch via gitlab api

Viewed 47

I need to pull BRANCH-1 to BRANCH-2 using the GitLab API. I don't see any similar features in the API. Merge Request only allows you to merge MR with the ability to compare SHA with HEAD. Rebase has no parameters for selecting a branch. Is there any way to do this?

1 Answers

If you're trying to overwrite BRANCH-2 so it exactly matches BRANCH-1, then you can do that by deleting BRANCH-2 and then recreating BRANCH-2 from BRANCH-1.

This is obviously a destructive operation, so don't do it if BRANCH-2 has unique changes that you need to keep. With that warning in mind, here's how you do it.

Delete BRANCH-2 with this API request:

DELETE /projects/:id/repository/branches/:branch

where :id is the ID or URL-encoded path of the project and :branch is the name of BRANCH-2.

Then recreate BRANCH-2 with this API request:

POST /projects/:id/repository/branches?branch=:branch&ref=:ref

where :id is the ID or URL-encoded path of the project, :branch is the name of BRANCH-2, and :ref is the name of BRANCH-1.

Related