是否可以临时更改"git push remote master"的ssh用户而不会搞乱.git/config或"git remote",或者使用整个远程url?
[root@host gitrepo]# git push otheruser@remote master # this does not work, but how great it would be
[root@host gitrepo]# USER=otheruser git push remote master # still asks password for root
Run Code Online (Sandbox Code Playgroud)
HiB*_*HiB 38
您是否尝试过使用整个远程URL?
git push ssh://<temp_user>@<host>/<repo_path> <local_branch>:<remote_branch>
Run Code Online (Sandbox Code Playgroud)
系统将提示您提供密码
Jes*_*sme 19
完成提交后,您可以使用以下语法:
git push https://<username>@github.com/<github repository> <local branch name>:<remote branch name>
Run Code Online (Sandbox Code Playgroud)
系统会要求您输入github密码来处理推送.
例如,如果你的GitHub用户名是"foobar的"资料库克隆的网址为" https://github.com/bar/ish.git ",以及本地和远程分支命名为"现时",你可以使用下面的:
git push https://foobar@github.com/bar/ish.git nonce:nonce
Run Code Online (Sandbox Code Playgroud)
我用
git push https://github.com/${userName}/${repoName}
Run Code Online (Sandbox Code Playgroud)
它会提示您输入用户名和密码
在git remote注册的ssh地址可能已包含用户名,因此您需要使用完整的ssh url,如:
otheruser@remote:arepo
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为ssh将使用默认的公钥/私钥(当前由第一个用户用于身份验证).
您可以在本地配置中注册新的遥控器:
# use the current ssh address registered for origin, changing just the user
# but you need a config file
git remote add originOtheruser otheruser:arepo
Run Code Online (Sandbox Code Playgroud)
你必须有一个$HOME/.ssh/config
文件,以便定义ssh条目'otheruser',因为ssh需要知道它需要使用哪个公钥/私钥:它不能是默认的($HOME/.ssh/id_rsa
和$HOME/.ssh/id_rsa.pub
)
例如,参见" 如何在github上为1个用户添加2个repo的部署密钥 "
Host otheruser
HostName remote
User otheruser
IdentityFile ~/.ssh/otheruser
Run Code Online (Sandbox Code Playgroud)
假设您已将其他用户的公钥/私钥存储为:
$HOME/.ssh/otheruser
$HOME/.ssh/otheruser.pub
Run Code Online (Sandbox Code Playgroud)
现在,您可以使用新的遥控器来推送:
git push originOtheruser master
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
71815 次 |
最近记录: |