Get latest updates from master into my branch

Viewed 23232

I created a branch called myBranch from master. Other colleagues have done so and merged their branches into master. So my branch is different from master now. How can I get the latest version of master into myBranch? I found on stackoverflow the answer is:

git checkout myBranch      # gets you "on branch myBranch"
git fetch origin        # gets you up to date with origin
git merge origin/master

I do not want to ruin the master branch and make a mistake. Would you please let me know if this is the right approach to get latest changes from master into mybranch?

3 Answers
  1. checkout to your branch- myBranch

    git checkout myBranch

  2. get latest code from master branch to your branch

    git pull origin master

First make you local master upto date

git checkout master

git pull --rebase // You can choose to merge here also.

Then go to your branch. Rebase master onto it.

git checkout <branch>

git rebase master

You might get merge conflicts. Fix them if any.

Now your branch will have all changes that master has... plus the changes that are specific to your branch alone.

You certainly should merge the master into your branch. Our colleagues will certainly explain how to do the technical part for you.

But I would like to add one point.

If you are afraid to make any mistake, instead of merging it directly to your branch or into the master, you could create a separate temporary branch only to merge the master to your branch and discover if it will cause any problem. If it causes any problem, you could use the branch you created to discover how to resolve it.

Finally, after the experiment within this temp branch, you could delete it and merge master into your branch, knowing how to securely not ruin the branches. :)

Related