When creating a merge request in gitlab I often get a message: Request to merge branch-A into develop ([x] commits behind) what does gitlab want to tell me? should I worry or do I need to fix something (what)?
Git merge requests (MR) are the foundation of the GitLab version control platform. They are called merge requests because their final action is merging the branch with the main feature branch. Git merge combines changes into one consistent tree, just one part of what Git pull does.
In Gitlab, the merged status means the relevant commits have been merged and no action is needed. A closed merge request is one that has been put aside or considered irrelevant. It is therefore not merged into the code base.
Yes you can being on a new branch doesn't stop you from using a commit.
After some time a merge request is open in a project it is normal that the version of the branch you are trying to merge into becomes outdated due to other people merging their own changes to it.
Gitlab helps you by showing how much the version of the branch you updated is behind the remote branch.
Being behind will not set any hindrance to the act of merging, but it is a common practice to rebase
your commits on top of the branch your merging into. This will make your merge request updated by putting your commits chronologically after the ones that already are in that branch. That approach makes the work of the person responsible for the merge easier because the commiter himself has already resolved any conflicts that would have happened.
To do a rebase
following the scenario you proposed would be like this:
# Add a remote named `upstream` pointing to the original repository
git remote add upstream https://gitlab.example.com/example/your_project.git
# Fetch the latest commmits from `upstream`
git fetch upstream
# Checkout our branch-A
git checkout branch-A
# Rebase our branch on top of the `upstream/develop` branch
git rebase upstream/develop
# If needed fix any conflicts that may have appeared and then `git rebase --continue`
# Push the changes to the branch of your merge request
git push --force origin branch-A
Note: The --force
flag is necessary when you push because you are rewriting the commit history of origin/branch-A. From git's doc:
[--force] can cause the remote repository to lose commits; use it with care.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With