覆盖特定本地存储库的 Git 系统配置
Override Git system config for a specific local repository
我目前有两个 git 用户在同一台机器上使用两个不同的 Github 帐户存储库。
不知何故,在我看来,我在我的机器上设置的第一个用户总是在我尝试推送到原点时被考虑在内。当我尝试使用第二个用户进行推送时,我收到一条消息,指出第一个用户对第二个存储库没有权限。
我想作为第一步覆盖第二个 repo 中的 'system' 配置,但是如果知道 git 通常是如何在 Mac 上配置的就更好了机器,如何让链接到多个 Github 帐户的多个用户在同一台机器上共存?
要在本地存储库上设置用户,运行 这些命令位于存储库的根目录下。
git config user.name "Your Name Here"
git config user.email your@email.com
要在全局级别设置用户,运行 这些命令
git config --global user.name "Your Name Here"
git config --global user.email your@email.com
默认情况下,SSH 将根据密钥在系统上的命名或 SSH 代理中的名称,以固定顺序使用密钥。听起来您在推送到 GitHub 时总是使用相同的密钥,导致您始终使用相同的用户。
处理此问题的最简单方法是为 GitHub 创建一个使用适当身份的 SSH 别名。例如,在您的 ~/.ssh/config
文件中,您可以
Host github-user1
HostName github.com
User git
IdentityFile ~/.ssh/user1
IdentitiesOnly yes
Host github-user2
HostName github.com
User git
IdentityFile ~/.ssh/user2
IdentitiesOnly yes
然后,配置您的 Git 遥控器使用 github-user1
或 github-user2
作为主机名而不是 github.com
。例如,git remote set-url origin github-user1:git/git.git
.
我目前有两个 git 用户在同一台机器上使用两个不同的 Github 帐户存储库。
不知何故,在我看来,我在我的机器上设置的第一个用户总是在我尝试推送到原点时被考虑在内。当我尝试使用第二个用户进行推送时,我收到一条消息,指出第一个用户对第二个存储库没有权限。
我想作为第一步覆盖第二个 repo 中的 'system' 配置,但是如果知道 git 通常是如何在 Mac 上配置的就更好了机器,如何让链接到多个 Github 帐户的多个用户在同一台机器上共存?
要在本地存储库上设置用户,运行 这些命令位于存储库的根目录下。
git config user.name "Your Name Here"
git config user.email your@email.com
要在全局级别设置用户,运行 这些命令
git config --global user.name "Your Name Here"
git config --global user.email your@email.com
默认情况下,SSH 将根据密钥在系统上的命名或 SSH 代理中的名称,以固定顺序使用密钥。听起来您在推送到 GitHub 时总是使用相同的密钥,导致您始终使用相同的用户。
处理此问题的最简单方法是为 GitHub 创建一个使用适当身份的 SSH 别名。例如,在您的 ~/.ssh/config
文件中,您可以
Host github-user1
HostName github.com
User git
IdentityFile ~/.ssh/user1
IdentitiesOnly yes
Host github-user2
HostName github.com
User git
IdentityFile ~/.ssh/user2
IdentitiesOnly yes
然后,配置您的 Git 遥控器使用 github-user1
或 github-user2
作为主机名而不是 github.com
。例如,git remote set-url origin github-user1:git/git.git
.