Search code examples
gitgitlabpull-requestgit-pushgit-pull

forgot to git pull before git push


I just pushed an update branch with some changes to my GitLab origin repo (which I have forked from another repo on GitLab) and created a merge request (to merge the pushed branch into the upstream repo, where I have forked my origin from). It showed me a merge conflict.

Problem:
at the time I have forked off the update branch from the master branch, my master wasn't up to date anymore (there were already some changes on the upstream master)

Question:
how can I fix this (I want my commits on top of those commits of the upstream master)? Is it possible to kind of sync my local master with the upstream master and then to incorporate these additional commits in my update branch, push that "updated" update branch to my origin and finally make a new pull request?

Edit:

That is the current situation:

enter image description here

The orange commits (3 and 4) were introduced on upstream after I have forked the repo. So they are not present in my origin and subsequently not in my local repo. So when I push the update branch (commits 5 and 6) to my origin and create a merge request, then I get the error "merge conflict" because these commits are missing in my pushed update branch and subsecently in the merge request (at least that is what I think, why the merge conflict occurs - or could this also have another cause?).

So the solution would be, to somehow get those newly introduced commits (3 and 4) in my origin and from there into my local repo. And then I could create an "updated" update branch containing everything, which I could then push to my origin and create a new merge request. Like so:

enter image description here

Is this possible to achieve?


Solution

  • You basically want to rebase your branch:

    git checkout update
    
    # Fetch commits from upstream
    git fetch upstream
    
    # Replay the commits of your update branch over master branch of upstream
    git rebase upstream/master
    

    Note: this does not update your local master but you don't necessarily need to.