如何在远程服务器上为 git commit、git pull、git push 和 pull 创建 bash 或 zsh 别名?

How can I create a bash or zsh alias for git commit, git pull, git push and pull on a remote server?

如果我在终端中输入以下内容,我可以完成我想要的一切:

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

我想在 ~/.zshrc 中创建一个别名。类似于:

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

像这样在终端中 运行:

pushit "my commit message"

相反,每次我重新加载 ~/.zshrc (source ~/.zshrc) 或打开一个新终端 window 时,我都会看到它循环遍历我的别名数十次。目前还不清楚它实际上 运行s.

我做错了什么?

备注:

  1. 这不适用于关键任务服务器。它仅供个人使用。我知道这是糟糕的形式。
  2. 我不想使用 git 的 [别名] 工具,这样我就可以将所有别名放在同一个地方 (~/.zshrc)。

您想要一个函数而不是别名:

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