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

标签 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'

我想在我的 ~/.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) 或打开一个新的终端窗口时,我都会看到它循环遍历我的别名数十次。目前尚不清楚它是否实际运行。

我做错了什么?

注意事项:

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

最佳答案

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

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

关于bash - 如何在远程服务器上为 git commit、git pull、git push 和 pull 创建 bash 或 zsh 别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32830924/

相关文章:

php - 我正在将文本从 bash 脚本传递到 php。除 mount 和 unmount bash 命令外,一切正常。我究竟做错了什么?

bash - 无法恢复我的登录 shell

带通配符的 Git rm 找不到现有文件

linux - 通过 ssh 运行程序失败并显示 "Error opening terminal: unknown."

terminal - 如何在xshell中启用数字键盘?

macos - 无法在 Mac OS 10.8 中从终端使用 svn 命令

linux - 如何更改所有用户和所有 shell 的路径?

macos - iTerm2 右大括号不起作用

linux - 使用 tr 命令读取权限

git - 如何一次删除所有git别名?