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

Rya*_*yan 2 bash terminal zsh zshrc zsh-alias

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

git commit -am "my commit message" ; git pull ; git push ; ssh user@server 'cd /path/to/git/repo/ ; git pull ; exit'
Run Code Online (Sandbox Code Playgroud)

我想创建与我的别名相同的~/.zshrc.就像是:

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

像这样在终端中运行:

pushit "my commit message"
Run Code Online (Sandbox Code Playgroud)

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

我究竟做错了什么?

笔记:

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

hek*_*mgl 5

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

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