This one
git checkout -b #1-my-awesome-feature
creates error
error: switch `b' requires a value
escaping it with backslash or wrapping it in quotes will work
git checkout -b \#1-my-awesome-feature
but strange enough this
git branch #1-my-awesome-feature
will not produce any error and if you check if it is created with
git branch --all
there is no branch.
If hash char is not in the first position of the branch name, branch will be created.
git branch feature-#1
Executing git branch
feature-#1
* master
So my question is how hash (#) char is 'translated' in terminal and why it is not working when it is at first place?
Thanks!
Git imposes the following rules on how references are named: They can include slash / for hierarchical (directory) grouping, but no slash-separated component can begin with a dot . or end with the sequence . lock . They must contain at least one / .
Use hyphens as separators This is a little opinionated, but hyphens make for good separators in branch names. You could use an underscore, _ , too. The key is to be consistent, though. And that's it — just these three rules to keep in mind.
#
means a comment is starting (atleast in a linux shell). So
git checkout -b #1-my-awesome-feature
becomes:
git checkout -b
and throws error that b
option requires a value.
As shown here, you can solve this by escaping the #
with a \
or by putting the name in single/double quotes:
git checkout -b \#1-my-awesome-feature
git checkout -b "#1-my-awesome-feature"
git checkout -b '#1-my-awesome-feature'
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