Git使用记录
github SSH密钥
1.设置git的user name和email:
$ git config --global user.name "xxx"
$ git config --global user.email "xxx@gmail.com"
2.生成SSH密钥过程:
cd ~/.ssh #查看是否已经有了ssh密钥,如果没有密钥则不会有此文件夹,有则备份删除
$ ssh-keygen -t rsa -C “xxx@gmail.com” #生成SSH密钥,按3个回车,密码为空。
ssh-add filename #添加密钥到ssh
#在github上添加ssh密钥,这要添加的是“id_rsa.pub”里面的公钥
ssh git@github.com #测试
Warning: Permanently added 'github.com,192. ... .113' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
如果your_name正确显示你的ID,则说明成功设置了SSH公钥
添加SSH keys
ssh-keygen -t rsa
//系统提示输入文件保存位置等信息,连续敲三次回车即可
//在.ssh文件夹下生成了2个文件,一个公钥和一个私钥文件, id_rsa id_rsa.pub
//生成的SSH key文件保存在中~/.ssh/id_rsa.pub
cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
//命令:这样配置之后就可以实现无密码登录本机
//如果需要登录到远程主机,只需要将authorized_keys文件发送到远程主机的~/.ssh/目录下。
vim ~/.ssh/id_rsa.pub
//接着拷贝.ssh/id_rsa.pub文件内的所以内容,将它粘帖到github帐号管理中的添加SSH key界面中
打开github帐号管理中的添加SSH key界面的步骤如下:
1. 登录github
2. 点击右上方的Accounting settings图标
3. 选择 SSH key
4. 点击 Add SSH key
上传代码
echo "some remarks" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/xxx/xxx.git
git push -u origin master
Error:Agent admitted failure to sign using the key
//解決方式 使用 ssh-add 指令将私钥 加进来 (根据个人的密匙命名不同更改 id_rsa)--实现无密码登录
$ ssh-add ~/.ssh/id_rsa
$ git push -u origin master
Counting objects: 80, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (75/75), done.
Writing objects: 100% (80/80), 2.45 MiB | 248.00 KiB/s, done.
Total 80 (delta 20), reused 0 (delta 0)
remote: Resolving deltas: 100% (20/20), done.
To git@github.com:Vanessa-feng/xxx.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
github 删除文件
//先删除本地文件
$ git add.
$ git commit -m "delete file"
$ git push
//直接删除github文件
git rm filename
git commit -m "remove file"
git push -u origin master