朋友和我一起分享我的电脑.我已经在Windows 7上使用git bash shell推送到GitHub.现在我们在该计算机上的一个不同的项目,我需要她推送到她的帐户.但它一直试图使用我的用户名并说我无法访问她的存储库:
$ git push her_github_repository our_branch
ERROR: Permission to her_username/repository.git denied to my_username.
fatal: The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)
s-h*_*ter 162
这对我有用,它会提示输入用户名和密码
git config --local credential.helper ""
git push origin master
Run Code Online (Sandbox Code Playgroud)
Sim*_*ias 79
如果您使用不同的Windows用户,您的SSH密钥和git设置将是独立的.
如果这不是您的选择,那么您的朋友应该将您的SSH密钥添加到她的Github帐户.
虽然,以前的解决方案会让你自己推动,但它会让你进入她的回购.如果您不想在同一台PC上的不同文件夹中工作,可以通过删除-gconfig命令的标志在git文件夹中本地设置用户名和电子邮件:
git config user.name her_username
git config user.email her_email
Run Code Online (Sandbox Code Playgroud)
或者,如果您推送https协议,Github将每次都提示输入用户名/密码(除非您使用密码管理器).
tho*_*ong 31
您可以使用不同的帐户进行推送.例如,如果您的帐户是A,该帐户存储在.gitconfig中,并且您希望使用帐户B,该帐户B是您要推送的回购的所有者.
帐户B:B_user_name,B_password
SSH链接示例:https://github.com/B_user_name/project.git
B账户推送是:
$ git push https://'B_user_name':'B_password'@github.com/B_user_name/project.git
Run Code Online (Sandbox Code Playgroud)
要在.gitconfig中查看帐户
$git config --global --list$git config --global -e (也改变帐户)小智 20
请按照以下步骤操作:
# you can check what's currently:
git config user.name
git config user.email
git config user.name "your_github_username"
git config user.email "your_github_email"
# Again check what's currently:
git config user.name
git config user.email
Run Code Online (Sandbox Code Playgroud)
git log
# once you're confirmed that it's tagged to you, then you should move to step 3
Run Code Online (Sandbox Code Playgroud)
如果作者错了,那么您可以轻松撤消上次提交而不会丢失更改
另外,在转到第 3 步之前,不要忘记按照第 1 步进行完整性检查。!
git config --local credential.helper ""
git push
# it will ask you to enter your github_username and github_password
Run Code Online (Sandbox Code Playgroud)
cho*_*ovy 18
我使用自定义设置了ssh别名,IdentityFile并重写了原点以使用我的自定义me-github主机名.
#when prompted enter `id_rsa_user1` as filename
ssh-keygen -t rsa
# ~/.ssh/config
Host user1-github
HostName github.com
Port 22
User git
IdentityFile ~/.ssh/id_rsa_user1
#check original remote origin url
git remote -v
origin git@github.com:user1/my-repo.git
#change it to use your custom `user1-github` hostname
git remote rm origin
git remote add origin git@user1-github:user1/my-repo.git
Run Code Online (Sandbox Code Playgroud)
Luk*_*ski 13
如果在运行git pushGit后要求输入密码user,但是你想推送new_user,你可能想要使用git config remote.origin.url:
$ git push
user@my.host.com:either/branch/or/path's password:
Run Code Online (Sandbox Code Playgroud)
此时使用^C退出git push并使用以下推送为new_user.
$ git config remote.origin.url
user@my.host.com:either/branch/or/path
$ git config remote.origin.url new_user@my.host.com:either/branch/or/path
$ git push
new_user@my.host.com:either/branch/or/path's password:
Run Code Online (Sandbox Code Playgroud)
Dav*_*les 13
如果使用SSH URL(git@github.com:username/projectname.git)而不是HTTPS URL,则可以使用$GIT_SSH_COMMAND环境变量临时指定其他SSH密钥:
$ GIT_SSH_COMMAND="ssh -i different_private_key" git push
Run Code Online (Sandbox Code Playgroud)
据我所知,使用SSH URL,GitHub不关心用户名,只关心密钥:如果用户帐户有权访问存储库,并且该帐户有SSH密钥(请参阅帐户中的SSH密钥页)设置),然后如果您使用该SSH密钥推送到该存储库,推送将被视为来自该用户.
The*_*ool 12
我喜欢这样做最好。
git push https://username@github.com/username/repo
Run Code Online (Sandbox Code Playgroud)
这将提示输入密码,因此您不必在 shell 中以纯文本形式写入密码。
Kri*_*rya 10
克隆时很简单,请使用您的用户名获取git URL.提交时会询问您的新用户密码.
例如:
git clone https://username@github.com/username/reponame.git
git clone https://username@bitbucket.org/username/reponame.git
我一直在使用一台机器将代码推送到两个不同用户名的不同 GitHub 帐户。假设您已经设置了一个帐户并想添加一个新帐户:
ssh-keygen -t rsa -C "myaddress@example.com"id_rsa。给它一个不同的名字,例如id_rsa_another设置 -> SSH 和 GPG 密钥 -> 新建 SSH 密钥 ->给标签并粘贴密钥-> 添加 SSH 密钥
ssh-add ~/.ssh/id_rsa_anothertouch ~/.ssh/config并通过为您的帐户提供配置来编辑该文件:#first account
Host github.com-first
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
#another account
Host github.com-another
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_another
Run Code Online (Sandbox Code Playgroud)
现在您应该能够根据您添加到 ssh 代理的密钥从不同的帐户推送,即使用您的第一个帐户,请执行
ssh-add ~/.ssh/id_rsa.
您可能还想更改您的用户电子邮件:
git config --global user.email "myaddress@example.com"
或者在将代码推送到其中一个帐户时出现权限错误时清除 ssh 密钥:
ssh-add -D
我不知道如何在一台机器上拥有第二个 github 身份(这些答案都不适合我),但我确实弄清楚了如何能够像我自己一样推送到多个不同的 github 帐户。
为你的第二个 github 帐户设置第二个 SSH 密钥(像这样)
帐户之间的更改如下:
使用我新的第二个 github 帐户进行推送
ssh-add -D
ssh-add ~/.ssh/ssh_key_for_my_2nd_account
git push
Run Code Online (Sandbox Code Playgroud)
使用我的主帐户推送
ssh-add -D
ssh-add ~/.ssh/id_rsa
git push
Run Code Online (Sandbox Code Playgroud)
如前所述,您可以使用
git config user.name her_username
git config user.email her_email
Run Code Online (Sandbox Code Playgroud)
为单个 repo 手动设置用户名和电子邮件,但您必须添加以下命令:
git commit --amend --reset-author
Run Code Online (Sandbox Code Playgroud)
如果您在更改之前已经尝试推送。否则更改不会出现在配置文件中。
如果这是你的问题
remote: Permission to username1/repo.git denied to username2.
fatal: unable to access 'https://github.com/username1/repo.git/':
The requested URL returned error: 403
Run Code Online (Sandbox Code Playgroud)
除了使用git config更改终端的用户名和电子邮件:
$ git config --global user.name "Bob"
$ git config --global user.email "bob@example.com"
Run Code Online (Sandbox Code Playgroud)
您需要从Keychain中删除授权信息.这个解决方案花了我几个小时来弄明白.我发现我的钥匙串也有证书.
打开Keychain访问,单击All Items并搜索git.删除所有钥匙串
您可以使用以下命令为其他用户名添加新的远程 URLgit remote add origin-username https://username@github.expedia.biz/repository_name.git
此后,如果您按下 using git push -u origin-username master,系统将提示您输入密码。
git add .
git commit -m "initial commit"
git config --local credential.helper ""
git push https://github.com/youraccount/repo.git --all
Run Code Online (Sandbox Code Playgroud)
执行此推送命令后,将打开用户名密码提示。
| 归档时间: |
|
| 查看次数: |
174613 次 |
| 最近记录: |