I have to make a pull request to a repo.
I clone the project and it has only one branch : master
I checkout a new branch feature
and commit my changes to this branch.
I push my branch to Github and I'm now able to make a pull request. So I do it but it tells me now that I have conflicts.
I understand the problem. master
is ahead of feature
because I didn't "pull" the last changes that have been made to master when I waas working on feature
.
How can I fix it ? How can I "pull" the last changes of master into my feature
branch ?
$ git checkout feature
$ git fetch
$ git pull origin master
Now conflicts should occur. Now if you want to keep master's changes
$ git status # See the untracked files (conflict files)
$ git checkout --theirs <file-name> # Accept the master's change
Or, If you want to keep yours (features
changes ):
$ git checkout --ours <file-name>
Add, commit and push in feature
branch
$ git commit -am <commit-message> # Add & Commit
$ git push origin HEAD # Push to remote feature branch
Fixing via merge:
git fetch origin # gets latest changes made to master
git checkout feature # switch to your feature branch
git merge master # merge with master
# resolve any merge conflicts here
git push origin feature # push branch and update the pull request
Fixing via rebase:
git fetch origin # gets latest changes made to master
git checkout feature # switch to your feature branch
git rebase master # rebase your branch on master
# complete the rebase, fix merge conflicts, etc.
git push --force origin feature
Note carefully that the --force
option on the push after rebasing is probably required as the rebase effectively rewrites the feature
branch. This means that you need to overwrite your old branch in GitHub by force pushing.
Regardless of whether you do a merge or a rebase, afterwards the conflicts should be resolved and your reviewer should be able to complete the pull request.
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