自定义git push

问题描述

每次PUSH 代码时都要写上当前环境下的分支

每次 git push origin
在这里插入图片描述
需要写上分支名 git push origin feature/20211223_8683_options

但每个仓库下的分支名又不一样。所以比较烦人

解决方案

直接使用Shell alias

文件名 ~/.zshrc

# 获取当前分支
git rev-parse --abbrev-ref HEAD

向当前分支push代码
alias pxsh="git push origin $(git rev-parse --abbrev-ref HEAD)"

向当前分支pull代码
alias pxll="git pull origin $(git rev-parse --abbrev-ref HEAD)"

使用git 的Alias

文件名 ~/.gitconfig

[core]
  editor = vim
[commit]
  template = /Users/shang/.gitcommit.txt
[alias]
  co = checkout
  st = status
  remote = remote -v
  pxsh = "!f() { if [ -z $1 ];then currentBranch=`git rev-parse --abbrev-ref HEAD`; git push origin $currentBranch; fi }; f"
  pxll = "!f() { if [ -z $1 ];then currentBranch=`git rev-parse --abbrev-ref HEAD`; git pull origin $currentBranch; fi }; f"
  
其他
#feat: 新功能
#fix: 修复bug
#optimize: 代码优化
#doc: 文档
#style: 格式化 ESLint调整等(不影响代码运行的变动)
#refactor: 重构(即不是新增功能,也不是修改bug的代码变动)
#test: 增加测试
#compile: 编译过程
#chore: 构建过程或辅助工具的变动
#影响范围:
#用于说明 commit 影响的范围,比如修改的登录页、账户中心页等
#主题:
#commit目的的简短描述,不超过50个字符

使用方式


pxll  # 拉取代码
pxsh  # 推送代码

git pxll # 拉取代码
git pxsh # 推送代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

从未、淡定

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值