문제

I understand that if I have a branch ready to merge with remote master, I need to do:

  1. git checkout 'my branch'

  2. git rebase master (rebase because I want simple history + my changes are minuscule enough to do that). But it will be rebase with my local master, not with origin master, correct?

  3. git checkout master

  4. git merge 'my branch' - this will do fast-forward merge and completes the process.

But how to do the same merge with remote master? I don't see any explicit explanation in the Internet. I cannot just checkout on origin master on the 3d step. What am I missing?

도움이 되었습니까?

해결책

The remote master is whatever the remote repo identifies as master. Whenever you fetch from the origin remote, git tags that remote's master commit as your origin/master (in your remotes refs).

The way to update a remote repo's refs is to push to it (which also sends any commits or whatever else is needed). So:

git checkout master       # or however you want to get `master` current with origin
git pull                  # ...
git checkout mybranch
git rebase master
git checkout -B master    # you know it's going to --ff, so just move the ref
                          # or, you could `git checkout master; git merge mybranch`
git push origin master    # push the new commits to the remote's `master`

다른 팁

You can simply rebase on top of the origin master like this

git rebase origin/master

Also you can skip 3. and 4. simple pushing your rebased branch to the origin/master

git push origin my_branch:master
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top