2

I tried to search this question, but none of them answered my question.

Please let me give an example:
I get two branches in the git server

origin/master
origin/feature

Branch 'feature' is branched out from 'master', as everybody else is working on 'master', I don't want to impact them, so I branched out 'feature' in my local and pushed it to remote.

As there are commits every on 'master', two days later, I want to pull the least code on my 'feature', is there a way that I could just merge code from 'origin/master' to 'origin/feature', then just pull the least 'origin/feature'.

I tried

git checkout origin/feature
git merge origin/master
git status # you would see that this is the lease code with lots of commits
git checkout feature
git pull

But, after i git pull, I got nothing, even those least commits are lost.

So I realized origin/feature in local would be just an image of origin/feature in remote. That's why my way didn't work.

The other way to meet my requirement is

git checkout feature
git stash
git pull origin master:feature
git push origin feature:feature # or just [git push]
git stash pop stash@{0}

And this is the way I use right now.

I'm wondering it there a way that I could just merge those two remote branches directly without pushing anything?

yang yu
  • 21
  • 1
  • 3

1 Answers1

1
#fetch latest changes in origin
git fetch origin

git checkout feature

#to sync feature with what you have now
git push origin feature

#merge locally, while you sit on feature
git merge origin/master
#now push the merge to the origin
git push origin feature
Mykola Gurov
  • 8,517
  • 4
  • 29
  • 27
  • thanks a lot for the answer. Actually, we use the same way, although, not the exactly the same commands. But in this way, we still need to `merge` branches locally, then `push` to remote. Can we just `merge` them in the remote server? – yang yu Jul 14 '15 at 06:08
  • No, in general you cannot merge on the server by git itself. You can do Pull Requests (or merge requests) on some git services (like github, atlassian stash, etc), which can be eventually merged, provided there are no conflicts, but at your workflow you will be better off by merging on your local. – Mykola Gurov Jul 14 '15 at 07:22