Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i create git branch and switch at a time when creating a branch

I am creating a branch with this command:

git branch my-branch

and switch to a newly created branch with another command:

git checkout my-branch

Any idea about creating a branch and switching with one command

like image 753
Happy Patel Avatar asked Aug 30 '25 15:08

Happy Patel


1 Answers

You can use checkout with -b to specify a new branch name

git checkout -b my-branch

From the docs

Specifying -b causes a new branch to be created as if git-branch were called and then checked out.

like image 147
Cory Kramer Avatar answered Sep 03 '25 02:09

Cory Kramer