How can we create different Merge requests with same branch? I'm working as example with the branch feature/task1
. I commited those changes and created one Merge Request. Now I want to use the same feature branch but I want to create a new Merge Request. How can I achieve this?

- 4,222
- 8
- 24
- 34

- 47
- 8
-
1There's a difference between being able to do something and whether it's a good idea to do so. After a merge (let's assume into master), it is customary to then branch a new feature branch off of master (which now contains your changes) to continue working. Why does this approach not work for you? Why do you want to merge the same branch more than once? What is the problem you're trying to solve? – Flater Aug 02 '22 at 09:10
1 Answers
If what you mean to do is split work on a feature in multiple partial PRs, sure there is no problem. However, you need to be careful with a number of scenarios:
push second part of the feature
Need to be careful not to push into the same remote branch as the first part if it hasn't been merged yet. If you did that, the first PR would be updated to include the changes that you mean to include in the 2nd PR.
Another problem is how you want people to see your changes in the PR. If you provide main
(for example) as the target branch, then the PR will show all changes, including the ones of the first PR. In cases like this I set the target branch to be the first PR branch so that only the changes of the second PR are visible. When the first PR is merged, then I change the target branch to be the real target branch.
Careful if you decide to rebase
If you develop the second part of the feature and you decide to rebase, you need to make sure to also rebase the changes of the first PR.
So, if could be done like this (after fetching, if working with a remote)
git checkout first-part-of-feature
git branch temp # leave a temp branch over here, we will need it later
git rebase upstream/main # or whatever branch
git push # push into the remote branch
# now let's rebase the second part of the feature branch
git rebase --onto first-part-of-pr temp second-part-of-pr
# and now you got the second part on top of the first part
# and now you can push