我从我的GitHub帐户克隆了一个Git存储库到我的电脑。
我想使用我的电脑和笔记本电脑,但只有一个GitHub帐户。
当我尝试使用我的电脑推送到GitHub或从GitHub中拉取时,它需要用户名和密码,但当我使用笔记本电脑时不需要!
我不想每次与origin交互时都键入用户名和密码。我在这里缺少什么?
我从我的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 push origin HEAD
你可以写:
git push https://user:pass@yourrepo.com/path HEAD
显然,对于大多数shell,这将导致密码被缓存在历史中,所以请记住这一点。
如果您克隆了HTTPS而不是SSH,并且在pull、push和fetch时遇到用户名和密码提示问题。您可以简单地为UBUNTU解决此问题
步骤1:移动到根目录
cd ~/
创建文件.git凭据
使用用户名密码和githosting URL将此内容添加到该文件
https://user:pass@example.com
然后执行命令
git config --global credential.helper store
现在,您将能够轻松推送并从回购中获取所有详细信息。
一个常见的原因是使用默认(HTTPS)而不是SSH进行克隆。您可以通过转到存储库,单击“克隆或下载”,然后单击URL字段上方的“使用SSH”按钮,然后更新源远程的URL,如下所示:
git remote set-url origin git@github.com:username/repo.git
您可以使用以下方法检查是否已将远程添加为HTTPS或SSH:
git remote -v
GitHub中记录了这一点:将远程URL从HTTPS切换到SSH。
块引用
如果您在请求用户名和密码时遇到$git推送代码问题,请执行以下步骤:
Login to your profile.
Go to settings
click developer settings
->Personal access tokens
--> note: access token
--->Select scopes: checkbox on repo
----> Generate token
-----> Make sure to copy and store it safely if you intend to reuse it.
*** use the generated token as password during pushing code for next 30days ***
***HAPPY CODING***
直接更新Git配置文件(如果不想记住花哨的命令):
在您喜爱的文本编辑器中打开.git/config文件。它将在您克隆的文件夹中或执行git init的存储库中。进入该存储库。git是一个隐藏的文件夹,按Ctrl+H应该会显示隐藏的文件夹(终端中的ls-a)。
下面是.git/config文件的示例。复制并粘贴这些行,并确保使用Git信息更新这些行。
[user]
name = Tux
email = tux@gmail.com
username = happy_feet
[remote "origin"]
url = https://github.com/happy_feet/my_code.git
fetch = +refs/heads/*:refs/remotes/origin/*
将SSH的URL部分更改为以下格式:
url = git@github.com:happy_feet/my_code.git
(以上格式不会随GitHub或Bitbucket等各种Git远程服务器而改变。如果您使用Git进行版本控制,则相同):
注意:连接到远程Git存储库的SSH方式将要求您将公共SSH密钥添加到Git远程服务器(如GitHub或Bitbucket。在设置页面搜索SSH密钥)。
要了解如何生成SSH密钥,请参阅:创建SSH密钥