I am trying to create a global git alias to delete a local and a remote copy of a branch in one command. I would like the alias to take the following input:
$ git purge myBranch
And generate the following commands:
$ git branch -d myBranch
$ git push origin --delete myBranch
Among many other attempts, I've tried this:
$ git config alias.purge '!sh "git branch -d $1; git push origin --delete $1"'
But I get this error:
sh: 0: Can't open git branch -d myBranch; git push origin --delete myBranch
fatal: While expanding alias 'purge': 'sh "git branch -d $1; git push origin --delete $1"': No such file or directory
How can I create a global git alias that accepts an argument and forwards it to two separate git commands in this fashion?
Update:
Per @Chris' suggestion I've tried out the following:
git config --global alias.purge '!git branch -d $1 && git push origin --delete $1'
Here is the result:
$ git purge test
warning: deleting branch 'test' that has been merged to
'refs/remotes/origin/test', but not yet merged to HEAD.
Deleted branch test (was 1316434).
error: dst ref refs/heads/test receives from more than one src.
error: failed to push some refs to 'git@github.com:testrepo/repo.git'
I've confirmed that this works properly if I run the commands directly:
$ git branch -d test && git push origin --delete test
warning: deleting branch 'test' that has been merged to
'refs/remotes/origin/test', but not yet merged to HEAD.
Deleted branch test (was b610eca).
To git@github.com:testrepo/repo.git
- [deleted] test