Git Alias - Multiple Commands and Parameters

2019-01-03 01:28发布

I am trying to create an alias that uses both multiple Git commands and positional parameters. There are Stackoverflow pages for each, and it would appear painfully obvious to do both, but I am having trouble.

As an example, I want to switch to branch foo and perform a status. So in my .gitconfig, I have:

  [alias] 
     chs = !sh -c 'git checkout $0 && git status'

which doesn't work. Whereas something like this will work.

chs = !sh -c 'git checkout $0'

echoes = !sh -c 'echo hi && echo bye'

Any insight would be appreciated.

8条回答
对你真心纯属浪费
2楼-- · 2019-01-03 02:17

Try this one:

[alias]
    chs = "!sh -c 'git checkout \"$0\" && git status'"

Call it like this: git chs master

查看更多
乱世女痞
3楼-- · 2019-01-03 02:19

It's possible to have multiline git alias by appending \ at the end of each line.

[alias] 
   chs = "!git checkout $1 \ 
          ; git status     \
         "
查看更多
登录 后发表回答