1

So I have two branches master and develop branch. Current site is live on develop branch. But now I have added all these changes to master branch. Now on the live site master branch has no changes, so I want to pull changes of master from git. But I don't want to checkout to master as site is live. Is there a way to pull changes from master into master on the server from another branch? I executed this command

   git fetch origin master

Is it correct?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Spidi
  • 109
  • 5
  • 13
  • Possible duplicate of [git: How to 'git pull' into a branch that is not the current one](http://stackoverflow.com/questions/18994609/git-how-to-git-pull-into-a-branch-that-is-not-the-current-one) – Jeen Broekstra Nov 01 '16 at 06:27
  • 1
    `git pull` = `git fetch` + `git merge` (or, if you tell it so, `git fetch` + `git rebase`). The second half, the merge-or-rebase, uses the current branch, so it's impossible to do in general. However, *if* (big if) the merge-or-rebase step will just do a "fast forward", there are some tricks that will work. See the linked Q&A. – torek Nov 01 '16 at 07:51

2 Answers2

1

If the desired update of the master branch is a fast forward (which probably should be the case, since I guess you do not do code updates in the live site), you can specify a refspec:

git fetch origin master:master

This will update the local master to the state of the remote master, assuming that the update is a fast forward. Look for description of refspec in git fetch documentation. Note that this method of updating refs cannot be used if local and remote master have diverged.

Alderath
  • 3,761
  • 1
  • 25
  • 43
1

you can use git pull origin master:master. Because current site is live on develop branch, it may cause some merge conflict for develop branch, just abandon it. If you want to review the local latest master branch, use git checkout -f master to switch.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74