Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use bash variable correctly in gitconfig with alias

This is my alias to create branch and set upstream on that branch later on:

create = !sh -c \"branch=$(git branch | peco) 
          && git fetch origin ${branch}:${1} 
          && git checkout $1 
          && git branch -u origin/$(git current) fix/$1\"

But no matter I execute the follow command, it keeps showing syntax error, like this: new-branch-name: develop: command not found

What do I need to do to make the above alias works? Thanks a lot!

like image 429
George Jor Avatar asked Jun 18 '26 05:06

George Jor


1 Answers

There is not such a command name current in git..

Here is your fix:

create = !sh -c \"branch=$(git rev-parse --abbrev-ref HEAD) && git fetch origin ${branch}:${1} && git checkout $1 && git branch -u origin/$(git rev-parse --abbrev-ref HEAD) fix/$1\"

On Multiple lines for easy reading:

create = !sh -c \"branch=$(git rev-parse --abbrev-ref HEAD) 
         && git fetch origin ${branch}:${1} 
         && git checkout $1 
         && git branch -u origin/$(git rev-parse --abbrev-ref HEAD) fix/$1\"
like image 137
CodeWizard Avatar answered Jun 19 '26 19:06

CodeWizard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!