Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

bash - Pipes in a Git alias?

I work on feature branches that have annoying big names, so I often end up grepping my current branch name when I need to push up to the feature branch from my local feature branch, like so:

git branch | grep '*' | sed 's/* //' | xargs git push origin

This works fine. I want to make this an alias, so I did this in ~/.gitconfig:

[alias]
   pushcur = branch | grep '*' | sed 's/* //' | xargs git push origin

Now, when I run git pushcur, I get the following error:

usage: git branch [options] [-r | -a] [--merged | --no-merged]

Leading me to believe that the alias is not properly parsing the pipes. Is there something else I should do to achieve the desired alias?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I don't think you can, but you can prefix it with an ! to treat the command as a new shell command

[alias]
    pushcur = ! git branch | grep '*' …

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...