Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

github

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?

like image 749
Kouta Osabe Avatar asked Mar 09 '23 08:03

Kouta Osabe


1 Answers

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.

like image 172
VonC Avatar answered Mar 14 '23 05:03

VonC