发现一个更好的做法,还可以与git-completion.bash兼容,实现tab自动补全
执行下面的配置,安装一个gpush子命令:
git config --global alias.gpush '!f() { : push ; r=$1; [[ -z $r ]] && r=origin; b=$2; t=$(awk "{ print \$2 }" $(git rev-parse --git-dir)/HEAD); t=${t#refs/heads/}; [[ -z $b ]] && b=$t; cmd="git push $r HEAD:refs/for/$b%topic=$t"; echo $cmd; echo; $cmd; }; f'
这样执行
git gpush
就自动转为
git push origin <当前分支>:refs/for/<当前分支>
执行
git gpush origin master
就自动转为
git push origin <当前分支>:refs/for/master