Creating and using a new branch involves two commands:
$ git branch new_branch_name $ git checkout new_branch_name
I tend to forget the latter, which can be annoying. Is there a way to do this using a single command? Perhaps using an alias, or something similar? I know I could write a shell function, but that seems a bit much work for such a simple and common task.
Bazaar does support this to some degree using the bzr branch --switch
notation.
The easiest way to create a Git branch is to use the “git checkout” command with the “-b” option for a new branch. Next, you just have to specify the name for the branch you want to create. To achieve that, you will run the “git checkout” command with the “-b” option and add “feature” as the branch name.
While writing the question, and finding “What is the difference between "git branch" and "git checkout -b"?” in the list of similar questions, I found the answer myself:
$ git checkout -b new_branch_name
I guess I was reading the man page for the wrong command, I was expecting this as part of the branch
command, not for checkout
. Quoting the man page for checkout
:
Specifying
-b
causes a new branch to be created as ifgit-branch(1)
were called and then checked out.
Just what I was looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With