Git/GitHub 推送到别人对我的回购的分叉

Git/GitHub push to someone else's fork of my repo

我创建了一个存储库,然后我的一位同事将其分叉。 昨天一起工作,我们在我的电脑上克隆了 他的 分支

git clone https://github.com/hisname/hisfork.git

并在本地分支上工作,跟踪由

创建的非主远程分支
git checkout -b localbranch origin/hisdevelopmentbranch

我试图推动这些变化进入

git push origin localbranch:hisdevelopmentbranch

认为 git 会询问他的用户名和密码。 我得到的错误是

Counting objects: 13, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (13/13), 2.33 KiB | 0 bytes/s, done.
Total 13 (delta 9), reused 0 (delta 0)
remote: Resolving deltas: 100% (9/9), completed with 6 local objects.
To https://github.com/hisname/hisfork.git
 ! [remote rejected] localbranch -> hisdevelopmentbranch (permission denied)
error: failed to push some refs to 'https://github.com/hisname/hisfork.git'

甚至在 他将我添加为合作者 到他的 fork 之后。 我寻找答案,但我明白了。通常我会看到类似 ssh clone 而不是 url 配置文件,但我认为它更容易!

编辑

.....$ git remote -v
origin  https://github.com/hisname/hisfork.git (fetch)
origin  https://github.com/hisname/hisfork.git (push)

很可能是您自己的用户被用来对 github 进行身份验证。

您可以修改您的 git 遥控器以指定您同事的 github 用户, 像这样:

git remote set-url origin git+ssh://hisname@github.com/hisname/hisfork.git

git remote set-url origin https://hisname@github.com/hisname/hisfork.git

您可以让您的同事将您作为 "collaborator" 添加到他对您的存储库的分叉中,Like so: Inviting collaborators on Github

编辑: 正如 OP 在评论中提到的,您还需要接受邀请 才能进行协作,然后才能进行协作(上面链接的文档中的第 8 步)。