假设在develop分支上,想将代码提交到master分支,通常需要许多git指令:

git stash
git pull --rebase
git push
git checkout master
git merge origin/develop
git push
git checkout develop
git stash pop

使用git config可以设置快捷指令,将这些指令一步实现:

git config --global alias.push-master '!git stash && git pull --rebase && git push && git checkout master && git merge origin/develop && git push && git checkout develop && git stash pop'

其中push-master是自定义的这条快捷的名称,--global表示全局设置

! 是用于配置复杂逻辑,不加的话会被识别成git指令,比如配置单条指令的简单别名时:git config --global alias.co checkout 和 git config --global alias.co '!git checkout'效果相同

设置完毕后可以执行git config --global --list 查看全局配置,可以看到刚才配置的这条指令

使用时只需要执行git push-master 即可代替开头的指令

如果想要修改快捷指令,只需要用git config重新设置上面的快捷指令覆盖即可

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐