In IntelliJ I was working on a new branch from a remote branch called stage
.
My branch was called PM-43655-stage
.
I committed my changes and did git push -u origin PM-43655-stage
. It created a merge request into the stage
branch. Now It shows that the source branch is 2 commits behind the target branch.
There is no merge conflicts though.
I get confused between git pull
and git fetch
and I'm not sure what to do in this case.
CodePudding user response:
This message means that the branch you're trying to merge into (stage
in this case) has advanced since you branched out of it to create your MR. If there are no merge conflicts it can still be merged, but it's usually a good practice to have it up to date before merging so you can make sure the CI runs on the actual code that that will get merged.
You can do this with git pull
, which both fetches the remote changes and applies them, but personally, I prefer to have more control and rebase myself in case there are conflicts I want to resolve:
git fetch origin
git rebase origin/stage
Once you're done with that, you'll need to push your updated branch:
git push --force origin PM-43655-stage
EDIT:
With regard to the issue of local changes you don't want to commit brought up in the comments, the easiest approach would probably be to stash them - i.e., put them aside while you pull and push, and then return them:
# Put your local changes aside
git stash save
# Pull the stage branch
git pull origin stage
# Push the updated branch
git push --force origin PM-43655-stage
# Retrieve the uncommited changes and go back to work
git stash pop