I want to change git branches by it's number
To show branches numbers I use this (with alias):
$ git br | nl
1 * master
2 test
Now I want to get branch name by it's number and pass it to git checkout:
echo $(git branch | sed "s|[* ]||g;$1q;d") | xargs git checkout
But how to pass '$1' from args to this command, supposing it have an alias?
Expected behaviour:
alias checkout='echo $(git branch | sed "s|[* ]||g;$1q;d") | xargs git checkout'
checkout 2 # checkout to branch test
echo $(…). – Kamil Maciorowski Dec 23 '20 at 18:17MY_BRANCH=$(git branch | sed "s|[* ]||g;$1q;d");git checkout "$MY_BRANCH", but still, how do I pass an arg to it? Look at "Expected behaviour" in my question – Alex Kosh Dec 23 '20 at 18:22