0

(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.


kgflying
  • 194
  • 9
  • 2
    `git fetch origin master:master`. Note that the answer is in your reference post which makes it a perfect duplicate. – Zeitounator Dec 17 '20 at 19:53
  • 2
    And if you are really concerned about your master branch being updated between your feature branch rebase and your master update, do it the other way arround and use the local ref: `git fetch origin master:master && git rebase master` – Zeitounator Dec 17 '20 at 19:58
  • 1
    Does this answer your question? [Merge, update, and pull Git branches without using checkouts](https://stackoverflow.com/questions/3216360/merge-update-and-pull-git-branches-without-using-checkouts) – evolutionxbox Dec 17 '20 at 20:00

1 Answers1

3

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.

CH.
  • 556
  • 1
  • 5
  • 16