I'm trying to write an alias to delete both a local and remote branch at the same time, but I can't figure out why the syntax is not working. In ~/.gitconfig
, I've tried the following aliases, but each produces the same result, which is unexpected:
[alias]
nuke = !sh -c 'git branch -D $1 && git push origin :$1'
and
[alias]
nuke = !git branch -D $1 && git push origin :$1
both produce:
$> git branch
* master
mybranch
$> git nuke mybranch
Everything up-to-date
$> git branch
* master
mybranch
Switching the order of the commands produces a different result, but also not entirely what I'm looking for:
[alias]
nuke = !git push origin :$1 && git branch -D $1
...
$> git branch
* master
mybranch
$> git nuke mybranch
Everything up-to-date
Deleted branch mybranch (was d719895)
$> git branch
* master
$> git push origin :mybranch
To git@github.com:biegel/repo.git
- [deleted] mybranch
When I run that command directly on the shell, it works nicely:
$> git branch
* master
mybranch
$> git branch -D mybranch && git push origin :mybranch
Deleted branch mybranch (was d719895
To git@github.com:biegel/repo.git
- [deleted] mybranch
$> git branch
* master
I've tried creating an alias in ~/.bashrc
, using git push origin --delete $1
and using a shell function with !f() { };
and nothing seems to take!
I'm ready to give up. Any thoughts on what I'm missing here?
Thanks.