4

I have a Mercurial alias that pushes a specified branch to the central repo:

[alias]
pushbranch = push -b

This works ok, but 90% of the time I want to push the current branch, which I currently do like so:

$ hg pushbranch `hg branch`

I though I might be able to just update the alias in my .hgrc like so:

[alias]
pushbranch = push -b `hg branch`

But this fails with:

pushing to branch`
abort: unknown branch '`hg'!

I found this answer for doing essentially this with Git, but the mechanism used there also does not work with Mercurial, I did:

[alias]
pushbranch = push -b '!sh hg branch'

and got:

pushing to ssh://hg@bitbucket.org/myteam/reponame
abort: unknown branch '!hg branch'!

Any suggestions?

Community
  • 1
  • 1
Adam Parkin
  • 17,891
  • 17
  • 66
  • 87

1 Answers1

4

In Mercurial, the alias must start with an exclamation mark to call out to the shell. Within such an alias, $HG is available to invoke Mercurial. E.g.:

[alias]
pushbranch = !$HG push -b `$HG branch`
Reimer Behrends
  • 8,600
  • 15
  • 19