如何从同一个系统帐户推送到与多个用户相同的来源(使用 SSH 密码)?
How to push to the same origin as multiple users (using SSH passkeys) from the same system account?
我正在尝试 Specify an SSH key for git push for a given domain 适应我的问题。我的情况的不同之处在于,我不想推送到多个域,而是始终推送到与来自一个 (Unix) 帐户的多个 (Git) 用户相同的域。
~/.ssh/config
设置为每个用户都有一个条目:
Host git-as-bob
HostName git.domain.tld
User git
IdentityFile /home/shared/.ssh/id_rsa-bob
IdentitiesOnly yes
Host git-as-alice
HostName git.domain.tld
User git
IdentityFile /home/shared/.ssh/id_rsa-alice
IdentitiesOnly yes
在一个存储库中,我进行了必要的更改,并且推送工作正常(注意:说 git push
应该不起作用,这就是第一个命令的目的。它不会不过很重要,因为默认公钥只能读取存储库)。
$ git remote set-url --push origin no_push
$ git remote add origin-bob git@git-as-bob:/repository1.git
$ git remote add origin-bob git@git-as-bob:/repository1.git
在这里,发生以下情况:
$ git push origin-bob master
Everything up-to-date
在第二个存储库中,我做了完全相同的事情,但结果不同:
$ git push origin-bob master
To git@git-as-bob:/repository2.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@git-as-bob:/repository2.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
请注意,git remote -v
returns 在两种情况下几乎相同(即,唯一的区别是 "repository1.git" 与 "repository2.git"。还要注意,在推送之前,两个存储库都与原点同步。在此处显示的示例中,实际上没有任何要推送的内容,但如果有,也会出现同样的问题。
如果这是一个好的方法,我该如何解决它?如果不是,进行此类设置的合适方法是什么?
I even tried rm -rf'ing the directories and git clone'ing them again. Doesn't change anything.
这确实不会改变任何事情:拒绝错误是因为 远程 端的内容。
如果您完全控制这些回购协议(并且在您的本地回购协议中有正确的历史记录),解决这种情况的最快方法是:
git push --force origin-bob master
然后您将在远程存储库中拥有相同的历史记录。
OP Rainer Verteidiger adds :
It turned out I had a mistake in adding some but not all of the new remotes.
After done right, it all works just the way I did it.
我正在尝试 Specify an SSH key for git push for a given domain 适应我的问题。我的情况的不同之处在于,我不想推送到多个域,而是始终推送到与来自一个 (Unix) 帐户的多个 (Git) 用户相同的域。
~/.ssh/config
设置为每个用户都有一个条目:
Host git-as-bob
HostName git.domain.tld
User git
IdentityFile /home/shared/.ssh/id_rsa-bob
IdentitiesOnly yes
Host git-as-alice
HostName git.domain.tld
User git
IdentityFile /home/shared/.ssh/id_rsa-alice
IdentitiesOnly yes
在一个存储库中,我进行了必要的更改,并且推送工作正常(注意:说 git push
应该不起作用,这就是第一个命令的目的。它不会不过很重要,因为默认公钥只能读取存储库)。
$ git remote set-url --push origin no_push
$ git remote add origin-bob git@git-as-bob:/repository1.git
$ git remote add origin-bob git@git-as-bob:/repository1.git
在这里,发生以下情况:
$ git push origin-bob master
Everything up-to-date
在第二个存储库中,我做了完全相同的事情,但结果不同:
$ git push origin-bob master
To git@git-as-bob:/repository2.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@git-as-bob:/repository2.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
请注意,git remote -v
returns 在两种情况下几乎相同(即,唯一的区别是 "repository1.git" 与 "repository2.git"。还要注意,在推送之前,两个存储库都与原点同步。在此处显示的示例中,实际上没有任何要推送的内容,但如果有,也会出现同样的问题。
如果这是一个好的方法,我该如何解决它?如果不是,进行此类设置的合适方法是什么?
I even tried rm -rf'ing the directories and git clone'ing them again. Doesn't change anything.
这确实不会改变任何事情:拒绝错误是因为 远程 端的内容。
如果您完全控制这些回购协议(并且在您的本地回购协议中有正确的历史记录),解决这种情况的最快方法是:
git push --force origin-bob master
然后您将在远程存储库中拥有相同的历史记录。
OP Rainer Verteidiger adds
It turned out I had a mistake in adding some but not all of the new remotes.
After done right, it all works just the way I did it.