简体   繁体   中英

Merge on the remote master branch

I am currently on a new branch on my device. I would like to merge the modifications I made to the remote branch master.

I think I have to follow this procedure, but I'm not certain :

git checkout origin master
git pull origin master
git merge "new_branch"
git push origin master

Does this procedure is good?
Is there a more efficient way to do the same thing?

You can simply fetch, and then merge

git checkout newbranch
git fetch
git merge origin/master

Here, fetch is enough to update your remote tracking branches (the ones in your .git/refs/remotes/origin ): you can merge directly from one of those, like origin/master .
I like git fetch because it won't change any file in your working tree, so it is a safe first step.
git pull would fetch plus merge into your current branch.

As an additional step, you can update your local master branch if you want.
I would recommend

git config --global pull.rebase true
git config --global rebase.autoStash true

That way, this is enough, even if you have made some local commits on master, and have some pending modifications:

git checkout master
git pull

Your suggested steps are fine (with a few modifications):

git checkout master      # removed origin
git pull origin master
git merge new_branch     # removed quotes
git push origin master

This approach is to update your local master branch with changes, then directly update the remote master . However, if you are using a repo provider like GitHub or Bitbucket, you may not be able to directly update the remote master branch. In this case, you would create a pull request from your branch to master , and you would actually do the merge in the opposite direction, namely you merge master into new_branch :

git fetch origin         # update origin/master
git checkout new_branch
git merge origin/master
git push origin new_branch

From here, you would create a pull request in GitHub or whatever service you are using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM