繁体   English   中英

如何重命名git命令

[英]How to rename git commands

我想重命名以下git命令:

而不是输入:

  • git checkout我想将其重命名为git co

  • git commit我想将其重命名为git cm

  • git push origin我想将其重命名为git po

我怎样才能做到这一点?

谢谢!

Pro Git手册中的“ Git别名 ”一章准确地显示了您所需要的:

git config --global alias.co checkout
git config --global alias.cm commit
git config --global alias.po 'push origin'

您要做的就是为$ shell(bash / csh / zsh / fish)创建所谓的“别名”。

试试这个著名的大卫·沃尔什的出色博客文章: https : //davidwalsh.name/alias-bash

但请注意:通过ssh在远程计算机上工作或切换计算机时,非标准别名会让您大失所望,如果您在脚本中使用别名,它们将不会在其他地方运行!

使用别名: 这是显示其工作原理的链接

您可以在.bash_profile文件中放入以下内容:

alias checkout='git checkout'
alias pull='git pull'
alias push='git push origin'
alias push_f='git push origin -f'
alias rebase='git rebase'
#...

然后source .bash_profile

现在您可以编写: checkout masterpush mastercheckout master

注意:声明别名时不能放置参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM