【问题标题】:working on two github accounts [duplicate]处理两个github帐户[重复]
【发布时间】:2018-03-11 05:56:06
【问题描述】:

我有两个 git hub 帐户。我是 Windows 用户,我使用 git bash 作为客户端。我正在做一个项目。我可以将我的项目推送到第一个 github 帐户。但是当我尝试推第二个时,它说没有权限。

$ git push -u origin master
remote: Permission to <secondUser>/<repo>.git denied to <firstUser>.
fatal: unable to access 'https://github.com/<secondUser>/<repo>.git/': The requested URL returned error: 403

任何人都可以提出一种将项目推送到第二个帐户的方法。

【问题讨论】:

标签: git github


【解决方案1】:

您应该使用ssh key。在配置文件(通常是~/.ssh/config)中,您可以为多个帐户定义多个别名,如下所示(例如在 Linux 中):

Host first_name 
HostName github.com
User git
IdentityFile ~/.ssh/key_for_first_name

Host second_name 
HostName github.com
User git
IdentityFile ~/.ssh/key_for_second_name

./.git/config的repository目录下可以这样设置:

[remote "first_account"]
    url = git@first_name:[your_first_github_name]/[repository_name].git
    fetch = +refs/heads/*:refs/remotes/first_name/*
[remote "second_account"]
    url = git@second_name:[your_second_github_name]/[repository_name].git
    fetch = +refs/heads/*:refs/remotes/second_name/*

在推动时你可以这样做:

git push first_account master:master
git push second_account master:second_master

您可以将此机制应用于 Windows 场景。希望这可以帮助。

【讨论】:

  • 感谢您的回复
【解决方案2】:

在您的电脑上生成 SSH 密钥,将此 ssh 密钥添加到您的两个帐户中。 然后就可以正常使用了。

【讨论】:

  • 感谢您的回复,但是当我要添加到第二个帐户时,它说密钥已在使用中。
  • code.tutsplus.com/tutorials/…她我找到了完整的答案
猜你喜欢
  • 2016-12-08
  • 2016-10-08
  • 2019-07-10
  • 2021-04-29
  • 2018-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-16
相关资源
最近更新 更多