Issue
I'm working on the following git alias
[alias]
pushup = !git push --set-upstream origin `git branch | egrep "^\*" | awk -F"*" '{print $NF}'`
which is supposed to do a git push while simultaneously setting the upstream to the current branch.
The command
git push --set-upstream origin `git branch | egrep "^\*" | awk -F"*" '{print $NF}'`
works fine by itself on the command-line but I get a bad config file error when I try to use it as a git alias.
Clearly I don't understand something about the format of git aliases. Anyone want to enlighten me?
Solution
I'm not sure what went wrong, but the following simplified alias works for me:
[alias]
pushup = !git push --set-upstream origin $(git branch | awk '/^*/{print $2}')
Instead of grepping for *
and then splitting on it, you could rely on awk
's splitting on whitespace to automatically get you the branch name as the second field, and use awk
do grep
's job as well.
Vim highlights \*
as an error, and when I try with it, I get the error you got (I'm using echo
for debugging :D):
So that's the cause of the error. I still don't know why.
I suppose you could also use the simpler command from this SO post:
[alias]
pushup = !git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD)
Answered By - muru Answer Checked By - Cary Denson (WPSolving Admin)