git提示:please tell me who you are,运行以下代码
git config --global user.name "your name"
git config --global user.email "your@example.com"
注意上面设置的用户名和邮箱是git提交代码时用来显示身份和联系方式的,并非是GitHub的用户名和邮箱
git如何使用ssh
- git支持两种传输协议
- https,若使用此协议,每次pull、push都会提示输入用户名和密码
- git,使用git协议在使用ssh密钥,这样可以免去每次都输账号密码的烦恼
- 具体步骤
- 先执行
cd ~/.ssh
在输入ls
查看当前目录下有哪些文件,如果只有known_hosts一个文件,说明本地没有公钥,需要我们生成一个。 - 此时输入
ssh-keygen -t rsa -C "you@example.com"
,然后一路enter下去 - 再去查看ssh文件夹下面有没有id_rsa id_rsa.pub known_hosts这几个文件,如果有的话上面操作就是成功的
- 查看生成的公钥
cat ~/.ssh/id_rsa.pub
- 登陆你的github帐户。点击你的头像,然后 Settings -> 左栏点击 SSH and GPG keys -> 点击 New SSH key
- 然后你复制上面的公钥内容,粘贴进“Key”文本域内。 title域,自己随便起个名字。
- 点击 Add key。
- 执行以下命令
ssh -T git@github.com
,验证下这个key是不是正常工作,如果生成Hi Robin-LEI! You’ve successfully authenticated, but GitHub does not provide shell access.这说明上面操作时成功的
- 先执行
- 修改git的remote url
git remote -v
,显示origin https://github.com/someaccount/someproject.git (fetch) origin https://github.com/someaccount/someproject.git (push)
- 如果是以上的结果那么说明此项目是使用https协议进行访问的(如果地址是git开头则表示是git协议)
- 使用
git remote set-url
来调整你的url。 git remote set-url origin git@github.test/someproject.git
- 然后你可以再用命令 git remote -v 查看一下,url是否已经变成了ssh地址。
- 然后你就可以愉快的使用git fetch, git pull , git push,再也不用输入烦人的密码了