Kouta Osabe
Kouta Osabe

Reputation: 121

How do I create a new branch from the existing remote branch on GitHub using CLI?

I'm a newbie to Git/GitHub.

Actually,I know how to create a new branch from the existing remote branch on GitHub by GitHub GUI Interface like below.

Creating and deleting branches within your repository

The CLI(Command Line) for this procedure is correct below?

git checkout -b new_branch_name origin/existing_branch_name_on_git_hub

Does anyone tell me a exact way?

Upvotes: 4

Views: 9154

Answers (1)

VonC
VonC

Reputation: 1329292

It is correct, once you have:

  • either cloned the GitHub repo
  • or do a git fetch, in order to update the remote branch

Then a git branch -av will show you all the branches including origin/existing_branch.

And you can create a new branch with

git checkout -b new_branch_name origin/existing_branch_name_on_git_hub

But on the first push, do:

git push -u origin new_branch_name

That will add an upstream (tracking) reference.

Upvotes: 9

Related Questions