Rebase a merge request
Rebase to the same base branch
If commits have been made in the base repository since the time when the issue fork was created, you may need to rebase the issue fork in order to prepare it to be merged into the base repository. For example, the merge request is against Drupal core 9.4.x, but since it was made, 9.4.x has moved forwards.
There are two cases:
- Commits were made in different areas of the repository from the changes you made in your merge request, so there are no conflicts. In this case, unless you are a maintainer and are merging in the merge request, you do not need to rebase at this time.
- Commits were made that conflict with the changes you made in your merge request, which you'll know because either the merge request links in the issue are showing up as red with a merge error notice on them, or an automatic test failed with a "Not currently mergeable" message. In this case, you need to rebase and fix the merge conflicts now so that the merge can be done by a maintainer later.
To rebase a merge request using Gitlab, assuming you're already set up to commit to it as described above (Cloning and committing code to an issue fork):
- Click the merge request link in the issue fork area. This will take you to the merge request overview page in GitLab. Below the Merge Request Pipeline and Code Quality information you should find branch information including how far behind the source branch is:

- If the changes in the "x commits behind" do not conflict with anything in the MR then you can rebase via the UI. There is no 'rebase' button, but just enter a comment with the single word
/rebaseincluding the leading / and this will trigger a rebase. - If the above automated rebase is not possible you can resolve conflicts via the UI.
Alternatively, you can perform the rebase locally:
- Fetch the changes from the base repository:
git fetch origin - Make sure the base branch is up to date. For example, this might be 9.4.x on Drupal core.
git checkout BASE_BRANCH_NAME
git pull - Return to the issue branch and run the rebase command to attempt to merge the changes from the base repository into the issue fork branch you are working in:
git checkout ISSUE_BRANCH_NAME
git rebase BASE_BRANCH_NAME - If the command works, you are done. If you see error messages in the merge, resolve the merge conflicts as in the Dealing with merge conflicts section of the Rerolling patches page.
- Push the changes to the repository.
- If you used the copy-paste commands at the top of the issue
git push --force-with-lease drupal-ISSUE_NUMBER - If you cloned the fork directly then
git push --force-with-lease origin
- If you used the copy-paste commands at the top of the issue
Rebase to a new base branch
When main development branch that a merge request was made against is no longer current, the merge request's branch will need to be rebased from the the original base branch to the new branch.
For example, when the merge request was created, it might be against Drupal core's 9.4.x branch. Later on, this branch is no longer being developed, and the merge request must be rebased onto the 9.5.x branch.
- First, follow the instructions above for rebasing a merge request to the same base branch. This making the issue branch up to date with the current base branch will help minimize rebase conflicts
- Fetch the changes from the base repository:
git fetch origin - Switch to the new target branch, e.g. 9.5.x:
git switch NEW_BASE_BRANCH_NAME - Ensure this is up to date:
git pull - Switch to the feature branch:
git switch FEATURE_BRANCH -
Determine the old base branch. This is not always the version that the issue is set to, as the feature branch may be quite out of date, and drupal.org issues have their version number automatically updated. The following may provide the branch name, in order of simplicity:
- Look at the target branch of the merge request
- Do a git log of the feature branch, and look for the first commit that has the issue fork remote's tip of a main branch. For example, '
(drupal-3226806/9.3.x)' - Do a git log of the feature branch, and look for the first commit whose log message starts with an issue number, for example, 'Issue #3224478'. Note the SHA of this commit, and do
git branch --contains COMMIT_SHA | sort -V. The lowest branch number in the list is probably the base branch.
-
Make a new feature branch. This is so that the old merge request remains on the old base branch, to allow work on a backport and for the benefit of users still on that version. It is a good idea to use a logical name such as a suffix based on the new base branch to keep the issue fork's branches easy to understand.
git switch -c NEW_FEATURE_BRANCH- Run the rebase command:
git rebase --onto NEW_BASE_BRANCH_NAME OLD_BASE_BRANCH_NAME
If you tried, for example, the command
git rebase --onto 9.5.x 9.4.x
and the old base branch does not have an upstream, you may get the errorfatal: Needed a single revision. invalid upstream '9.4.x'. In this case add the upstream into the command:
git rebase --onto 9.5.x drupal-ISSUE_NUMBER/9.4.xIf the command works, you are done. If you see error messages in the merge, resolve the merge conflicts. If there are merge conflicts which are very complex, it may help to do the rebase in several steps, advancing one core minor version each time. For example, starting from base branch of 9.3.x, rebase first to 9.4.x, then to 9.5.x, then to 10.0.x, and so on.
- Push the changes to the repository
- If you used the copy-paste commands at the top of the issue
git push --force-with-lease drupal-ISSUE_NUMBER - If you cloned the fork directly then
git push --force-with-lease origin
- If you used the copy-paste commands at the top of the issue
- Create a new MR with as its target the
NEW_BASE_BRANCH_NAME, or edit the existing one:- If you created the MR or have commit access to the target repository, you can change it yourself. On the MR click Edit and then choose the new target branch.


- If you don't have access to edit the MR, try to ping the creator of the MR. If they don't respond, create a new MR and try to copy over any open threads from the old MR to the new.
- If you created the MR or have commit access to the target repository, you can change it yourself. On the MR click Edit and then choose the new target branch.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.