George Jor
George Jor

Reputation: 61

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!

Upvotes: 3

Views: 353

Answers (1)

CodeWizard
CodeWizard

Reputation: 142034

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\"

Upvotes: 1

Related Questions