How to merge remote master to local branch
From your feature branch (e.g configUpdate
) run:
git fetch
git rebase origin/master
Or the shorter form:
git pull --rebase
Why this works:
git merge branchname
takes new commits from the branchbranchname
, and adds them to the current branch. If necessary, it automatically adds a "Merge" commit on top.git rebase branchname
takes new commits from the branchbranchname
, and inserts them "under" your changes. More precisely, it modifies the history of the current branch such that it is based on the tip ofbranchname
, with any changes you made on top of that.git pull
is basically the same asgit fetch; git merge origin/master
.git pull --rebase
is basically the same asgit fetch; git rebase origin/master
.
So why would you want to use git pull --rebase
rather than git pull
? Here's a simple example:
You start working on a new feature.
By the time you're ready to push your changes, several commits have been pushed by other developers.
If you
git pull
(which uses merge), your changes will be buried by the new commits, in addition to an automatically-created merge commit.If you
git pull --rebase
instead, git will fast forward your master to upstream's, then apply your changes on top.
I found out it was:
$ git fetch upstream
$ git merge upstream/master
Switch to your local branch
> git checkout configUpdate
Merge remote master to your branch
> git rebase master configUpdate
In case you have any conflicts, correct them and for each conflicted file do the command
> git add [path_to_file/conflicted_file] (e.g. git add app/assets/javascripts/test.js)
Continue rebase
> git rebase --continue