Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git shell command alias giving a "bad config file" error

Tags:

git

bash

shell

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?

like image 745
Mark Biek Avatar asked Apr 28 '26 20:04

Mark Biek


1 Answers

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):

enter image description here

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)
like image 173
muru Avatar answered Apr 30 '26 12:04

muru



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!