Git rebase VS git merge
--
If you have your own branch and the master branch is updated. How to update the master branch’s update to your own branch?
Git merge
git checkout -b newbranch #use this one if you don't have the newbranch before
git checkout newbranch
git merge origin/master
git push origin newbranch
Git rebase
git checkout newbranch
git fetch
git rebase origin/master
git push origin newbranch
If you have conflict after rebase, you need resolve those conflicts manually on terminal one by one. After that, when you type
git rebase --continue
And there is no error message, you can run the following to force push
git push -f origin <you_branch_name>
The difference between merge and rebase
It can be shown from the nice illustration below[2].
Rebase master and force push to feature branch
A nice discussion can be found in [3].
Reference
[2]https://medium.com/datadriveninvestor/git-rebase-vs-merge-cc5199edd77c