本文并不阐述任何概念性知识,仅仅只是做一个笔记,简单是使用步骤,如遇障碍,请Google一下
- 使用SSH 完成 Git 与 GitHub 的绑定
1. 生成 SSH key
ssh-keygen -t rsa
指定 RSA 算法生成密钥,之后就就会生成两个文件,分别为id_rsa和id_rsa.pub,即密钥id_rsa和公钥id_rsa.pub. 对于这两个文件
2. 添加 SSH key
github.com -> Settings -> SSH and GPG -> New SSH key
将公钥id_rsa.pub的内容粘贴到Key处的位置(Titles的内容不填写也没事),然后点击Add SSH key 即可。
3. 验证绑定是否成功
ssh -T [email protected]
- 把本地项目推送到github的命令
(1) 打开你的目录
cd demo
(2) 初始化版本库,用于生成git文件
git init
(3) 将所有文件添加到缓存区
git add *
(4) 提交当前工作空间的修改内容
git commit -m "first commit"
(5) 将仓库连接到远程服务器
git remote add origin <server>(就是上面你仓库的地址)
(6) 将改动推送到所添加的服务器上
git push -u origin master
在推送的时候如果出现如下错误:
warning: redirecting to https://github.com/178146582/dabai.git/ To http://github.com/178146582/dabai.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'http://github.com/178146582/dabai.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
查了一下错误的原因是github中的README.md文件不在本地代码目录中。所以我们把上面第六步分成两步:
git pull --rebase origin master:进行代码合并
git push -u origin master
最新评论