每个分支使用gitconfig [英] Using gitconfig per branch
本文介绍了每个分支使用gitconfig的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们公司使用许多定制的开源项目.每当我向上游分支机构捐款时,我都会更改为使用我的个人电子邮件地址/名称.有没有办法让每个分支都有gitconfig?
Our company uses many customized opensource project. Whenever I contribute upstream branch I have change to use my personal email/name. Is there any way to have gitconfig per branch?
例如我想要的是
[remote 'gerrit']
name = 'Personal Name'
[branch 'origin']
name = 'Name in company'
推荐答案
您可以为此使用结帐后挂钩.运行
You can use post-checkout hook for this. Run
$ touch .git/hooks/post-checkout
$ chmod a+x .git/hooks/post-checkout
将内容添加到post-checkout
脚本中(必要时编辑名称和分支)
Add contents to post-checkout
script (edit names and branches as neccessary)
#!/bin/bash
# $3 "0" - checking out file. "1" - checking out branch.
[[ "$3" == "0" ]] && exit 0
branch=$(git status --short -b | cut -d' ' -f2-)
case $branch in
gerrit*)
git config user.name "Personal Name"
echo "changed user.name to Personal Name"
;;
master*)
git config user.name "Company Name"
echo "changed user.name to Company Name"
;;
*)
echo "Some other branch, what should user.name be?"
;;
esac
这篇关于每个分支使用gitconfig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文