简体   繁体   中英

Git update master from some branch

While I'm in a branch B1 can I update the master from remote while staying in B1?
Ie not doing

git checkout master
git pull
git checkout B1

But something shorter?

It's possible to get your local master updated without leaving your local branch by:

git pull origin master:master

What this command does is to pull the remote master and update the local master.

Generally git pull origin pulls all the branches in origin . It's possible to get one single branch pulled by git pull origin <remote-branch> . Actually the last parameter is a refspec .

A refspec follows the format src:dst . In the case of git-pull , src refers to a remote branch and dst to a local branch. git pull origin master , will just pull the remote master but won't update the local one. git pull origin master:master , will pull the remote master and update the local one.

You run:

git fetch --all

or

git remote update

After that, the remote master will in remote-tracking branch origin/master , you will be able to see its progress just like it were the local branch master . You can choose a time to merge/rebase the local master later.

Explanation: most probably you have a pair of remote-tracking branch origin/master and local branch master . master starts from from origin/master at some moment and contains local changes. git pull (1) updates origin/master and (2) merge or rebase the local modifications with origin/master progress. (1) can be done by git fetch I recommended, and (2) in current implementation requires checking out master anyway, even if the changes are trivial to merge.

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