简体   繁体   中英

Git: update local master branch without checkout

(This question is related to Merge, update, and pull Git branches without using checkouts but different.)

On local machine, I have a feature branch (say feature_1) and master branch. I need frequently rebase the feature branch to master, etc by

git pull --rebase origin master

After this command, my feature branch will be updated.

Is it possible (how) to update local master branch without checkout it?

(My repro is on local feature branch). I tried "git pull master". But it prompted:

fatal: 'master' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

My current way is: After

git pull --rebase origin master (A)

I run

git checkout master

git pull (B)

git checkout feature1

It's bad because:

  1. Not convenient, especially feature_1 has temp change.
  2. I want local master and local feature branch stay on the same base commit. Because there are time gap between (A) and (B), they could reach different base commit.

Thanks.


First, pull the remote branch to your local master using

git fetch origin master:master

as mentioned in your linked question. Then, rebase on your local master branch with

git rebase master

to address point 2.

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