.gitconfig
通常存储在 user.home
目录中。
我在为公司A和公司B的项目工作时使用不同的身份(主要是姓名/电子邮件)。如何使用两个不同的Git配置,以便我的提交不会使用我的姓名/电子邮件?
.gitconfig
通常存储在 user.home
目录中。
我在为公司A和公司B的项目工作时使用不同的身份(主要是姓名/电子邮件)。如何使用两个不同的Git配置,以便我的提交不会使用我的姓名/电子邮件?
Find .gitconfig from the system
File Location For Windows : "C:\Users${USER_NAME}.gitconfig"
File Location For Linux : "/usr/local/git/etc/gitconfig"
Open .gitconfig file and add below lines as per your condition
[includeIf "gitdir:D:\ORG-A-PROJECTS\"]
[user]
name = John Smith
email = js@organizationx.com [includeIf "gitdir:~/organization_b/"]
[user]
name = John Doe
email = jd@organizationy.com
在尝试git stash
本地更改时,我遇到了一个错误。Git的错误信息是“请告诉我你是谁”,然后告诉我运行git config --global user.email "you@example.com"
和git config --global user.name "Your name"
来设置您帐户的默认身份。但是,您必须省略--global仅在当前存储库中设置身份。
#!/bin/bash
# setgit
#
# Script to manage multiple global gitconfigs
#
# To save your current .gitconfig to .gitconfig-this just run:
# setgit -s this
#
# To load .gitconfig-this to .gitconfig it run:
# setgit -f this
#
#
#
# Author: Jeffrey Stone <thejeffreystone@gmail.com>
usage(){
echo "$(basename $0) [-h] [-f name]"
echo ""
echo "where:"
echo " -h Show Help Text"
echo " -f Load the .gitconfig file based on option passed"
echo ""
exit 1
}
if [ $# -lt 1 ]
then
usage
exit
fi
while getopts ':hf:' option; do
case "$option" in
h) usage
exit
;;
f) echo "Loading .gitconfig from .gitconfig-$OPTARG"
cat ~/.gitconfig-$OPTARG > ~/.gitconfig
;;
*) printf "illegal option: '%s'\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
-s
在你的 Bash 脚本中没有被处理。 - Vadim Kotov%USERPROFILE%\.gitconfig
,并为每个您想要设置特定配置的公司添加以下行。[includeIf "gitdir:C:\\!work\\company_X\\"]
[user]
name = Some Guy
email = some.guy@X.com
[includeIf "gitdir:C:\\!work\\company_Y\\"]
[user]
name = Some Other Guy
email = some.other.guy@Y.com