简体   繁体   中英

Create a git branch off from origin/master

This is a question that is not similar to existing Q&A that I've found. It is closely related to the git workflow that I'm following, which is

  • I do git updates in the default master branch, so that I can do git pull from time to time.
  • My updates are pushed to a remote branch for PR.

Now the situation is that I need a quick fix and need to create a git branch from off from the real master on the server, not the master of my local change . But I was unable to do that following the advices I found on the internet.

My current status:

. . . 
On branch master
Your branch is ahead of 'origin/master' by 52 commits.
. . . 

$ git checkout master
Already on 'master'
Your branch is ahead of 'origin/master' by 52 commits.

git checkout -b new-feature
Branch 'new-feature' set up to track local branch 'master' by rebasing.
Switched to a new branch 'new-feature'

$ git status
On branch new-feature
Your branch is up to date with 'master'.

The problem is that such "up to date with 'master'" is the master of my local change, not the real master on the server, as it is tracking "local branch 'master' ", but I want it to base and track " origin/master " instead.

Just to clarify your problem to future readers...

You are working on the master branch which has a remote called origin/master .

You have made 52 commits to master and you are now ahead of origin/master .

You want to create a new branch, but you want to create the branch at the last commit where origin/master is.

To do this, you'll want to tell git to create a new branch at origin/master and then tell it to track origin/master

You can use:

git branch --track new-branch origin/master

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