我从我的GitHub帐户克隆了一个Git存储库到我的电脑。

我想使用我的电脑和笔记本电脑,但只有一个GitHub帐户。

当我尝试使用我的电脑推送到GitHub或从GitHub中拉取时,它需要用户名和密码,但当我使用笔记本电脑时不需要!

我不想每次与origin交互时都键入用户名和密码。我在这里缺少什么?


当前回答

 # gen  the pub and priv keys
 # use "strange" naming convention, because those WILL BE more than 10 ...
 ssh-keygen -t rsa -b 4096 -C "me@corp.com" -f ~/.ssh/id_rsa.me@corp.com@`hostname -s`

 # set the git alias ONLY this shell session
 alias git='GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa.me@corp.com.`hostname -s`" git'

 # who did what when and why
 git log --pretty --format='%h %ai %<(15)%ae ::: %s'

 # set the git msg
 export git_msg='issue-123 my important commit msg'

 # add all files ( danger !!! ) and commit them with the msg
 git add --all ; git commit -m "$git_msg" --author "Me <me@corp.com"

 # finally 
 git push

其他回答

检查您的git版本和更新。然后将解决问题

$git更新windows的git

更新说明:当您的PC git版本和服务器git版本不匹配时,我们可以使用此选项。

这就是对我有用的:

git remote set-url origin https://username@github.com/username/reponame.git

例子:

git remote set-url origin https://jsmith@github.com/jsmith/master.git

对于Mac OS

转到您的Github设置->开发者设置->Github中的个人访问令牌页面(https://github.com/settings/tokens/new),并生成具有所有Repo权限的新令牌在mac上搜索Keychain Access->搜索github.com->单击Show password,然后粘贴刚才复制的令牌。转到CLI,它将再次询问用户名和密码,输入您的Github用户名并将令牌粘贴为密码,您应该可以继续使用CLI。

 # gen  the pub and priv keys
 # use "strange" naming convention, because those WILL BE more than 10 ...
 ssh-keygen -t rsa -b 4096 -C "me@corp.com" -f ~/.ssh/id_rsa.me@corp.com@`hostname -s`

 # set the git alias ONLY this shell session
 alias git='GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa.me@corp.com.`hostname -s`" git'

 # who did what when and why
 git log --pretty --format='%h %ai %<(15)%ae ::: %s'

 # set the git msg
 export git_msg='issue-123 my important commit msg'

 # add all files ( danger !!! ) and commit them with the msg
 git add --all ; git commit -m "$git_msg" --author "Me <me@corp.com"

 # finally 
 git push

我刚刚遇到了同样的问题,我找到的最简单的解决方案是使用SSH URL而不是HTTPS URL:

ssh://git@github.com/username/repo.git

而不是这样:

https://github.com/username/repo.git

现在,您可以只使用SSH密钥而不是用户名和密码进行验证。