1

Assume I want to pull from remote branch named "FC-1000". I could create a new branch locally by "git checkout -b FC-1000" and then pull origin from remote. But locally, which branch should I be to create the new branch? For example, If I'm on FC-2000 and do "git checkout -b FC-1000", I will create the new branch FC-1000 from FC-2000.

xin buxu1
  • 397
  • 4
  • 16

5 Answers5

0

Following the GitHub documentation, this would be the best command to run: git branch -f new_local_branch_name upstream/remote_branch_name

It'll create a new branch and sync it to the remote branch in one line.

Oliver Dunk
  • 484
  • 5
  • 12
0

Let's say the remote branch is named origin/some-branch. If you have a recent version of Git, you can just type git checkout some-branch, and a local branch named some-branch will be automatically created that tracks origin/some-branch. It does not matter what branch you are on when you run this command.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54
0

Looks like the official recommendation is: git checkout -b [branch] [remotename]/[branch]or the shorthand git checkout --track origin/serverfix. (Source: https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches#Tracking-Branches) You may have to do a git fetch first, but I haven't been able to find official documentation saying so...

There's a lot of good commentary on your situation here: How do I check out a remote Git branch?.

Here's the full official git instructions: https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches

To answer the "letter" of your question: Most likely you would want to run your git checkout -b from the master branch. Otherwise it's whatever branch FC-1000 was created from.

Community
  • 1
  • 1
lostphilosopher
  • 4,361
  • 4
  • 28
  • 39
0

In such a case, you need to create a tracking branch. Just perform the following steps:

git fetch
git checkout --track origin/FC-1000

This will create a branch which will track the branch at origin.

Animesh Sharma
  • 3,258
  • 1
  • 17
  • 33
0

You do not need to create a local branch to pull. Just run

git pull origin FC-1000

From the branch to which you want to merge.

Matthieu Moy
  • 15,151
  • 5
  • 38
  • 65