I am trying to create a Git alias that will automatically initialize and publish a new branch. The alias is as follows:
[alias]
public-branch = !git checkout -b $1 && git config branch.$1.autosetuprebase always && git config branch.$1.mergeoptions --ff-only && git push -u origin $1
When I run each of the commands in the alias separately, they are successful. However, when running git public-branch feature, I get the following error output:
Switched to a new branch 'feature'
Username for 'https://github.com': my_username
Password for 'https://username@github.com':
error: dst ref refs/heads/feature receives from more than one src.
error: failed to push some refs to 'https://github.com/username/GitTestRepo.git'
The alias is successfully adding the first two config properties but is failing on the push command. I can see in my config file that the tracking information has not been successfully added:
[branch "feature"]
autosetuprebase = always
mergeoptions = --ff-only
This error also only occurs when the push command is the last command listed in the alias; if I put either of the git config commands after the push, the alias runs without a hitch. I'm guessing this is just a result of git not parsing the alias correctly but I can't see how to resolve the issue. Any input you can provide is appreciated.