28

I work in develop branch. Sometimes, when I want to push changes to origin, git say, that there are some changes in origin/master branch.

How to pull changes from remote master to local master without checkout to local master?

cexbrayat
  • 17,772
  • 4
  • 27
  • 22
nkuhta
  • 10,388
  • 12
  • 41
  • 54
  • Some more answers in a possible duplicate http://stackoverflow.com/questions/18994609/how-to-git-pull-into-a-branch-that-is-not-the-current-one – Olga Mar 17 '17 at 11:17
  • @Olga that question is similar, but is focused on `git fetch`, and generally not merging any code into your current branch. – Devin Rhode Dec 03 '22 at 02:30

2 Answers2

44

If you want to update your local master without checkout, you can do :

git pull origin master:master

That will update your local master with the origin/master

Or, as I assume that you want to ultimately rebase your develop branch with the changes occured in origin/master, you can do a simple git fetch, that will not touch your local branches :

git fetch

Now your origin/masteris up to date, so you can rebase or merge your local branch with these changes. For example, when you are in your develop branch :

git rebase origin/master

And your develop branch will be up to date with the changes.

cexbrayat
  • 17,772
  • 4
  • 27
  • 22
  • 9
    `git pull origin master:master` also pulls changes to your local develop branch – James Lin Jul 06 '15 at 22:08
  • 1
    Then either this answer should include the impact on local branch or modify the answer to something else. I would ask the original acceptor of this answer needs to unmark first and verify to give accept again. – swcraft Nov 16 '18 at 15:36
  • This answer is wrong. `git pull origin master:master` starts a rebase on my local – Lucien May 03 '23 at 11:29
0

Accepted answer will also pulls master into your actual branch.

git fetch
git branch -D master
git checkout --track origin/master
Melounek
  • 764
  • 4
  • 20