1

If I type the following into Terminal I can accomplish everything I want:

git commit -am "my commit message" ; git pull ; git push ; ssh user@server 'cd /path/to/git/repo/ ; git pull ; exit'

I'd like to create the same as an alias in my ~/.zshrc. Something like:

alias pushit () { git commit -am "$@" ; git pull ; git push ; ssh user@server 'cd /path/to/git/repo/ ; git pull ; exit' }

To be run in Terminal like so:

pushit "my commit message"

Instead every time I reload ~/.zshrc (source ~/.zshrc) or open a new Terminal window I see it loop through my alias dozens of times. It's not clear it actually runs.

What am I doing wrong?

Notes:

  1. This is not for a mission critical server. It's just for personal use. I know it's poor form.
  2. I'd rather not use git's [alias] tools so I can keep all of my aliases in the same place (~/.zshrc).
Ryan
  • 14,682
  • 32
  • 106
  • 179

1 Answers1

5

You want a function rather than an alias:

function pushit () { 
    git commit -am "$@"
    git pull
    git push
    ssh user@server -- 'cd /path/to/git/repo/ ; git pull'
}
hek2mgl
  • 152,036
  • 28
  • 249
  • 266