- 自己已经有了一个github的账号
创建SSH KEY
ssh-keygen -t rsa -C "youremail@example.com"
SSH Key创建成功后,在笔者的主目录下就会生成/home/yourname/.ssh
文件夹,里面也会生成文件id_rsa
与id_rsa.pub
,它们是SSH Key的秘钥对。其中id_rsa
是私钥,不能泄露,id_rsa.pub
是公钥,可以告诉其他人。
查看隐藏文件: 文件夹下Ctrl+H
在GitHub端设置SSH Key
登录GitHub,点击右上角头像,Settings -> Personal settings -> SSH and GPG keys。在SSH Keys标签右方点击New SSH Key。
弹出两个文本框。其中的Title,可以随意命名
另一个Key文本框,需要输入刚刚生成的id_rsa.pub文件中的内容。粘贴后点击Add SSH Key,即可生成SSH Key。
设置名字
git config --global user.name "555"
git config --global user.email "555@163.com"
接下来创建一个代码仓库(repository)
创建一个仓库:
- <span style="font-size:18px;">touch README.md
- git init
- git add README.md
- git commit -m "first commit"
- git remote add origin https://github.com/kezhenxu/android.git
- git push -u origin master</span>
这样,一个属于你自己的Github仓库就完成了,接下来就可以把自己的代码上传了,把Github当作一个代码备份和中转站确实是一个好主意,不过通过Github分享你的代码给所有人用或许才是Github更有价值的体现。
mkdir hellogithub
//向文件夹中添加.cpp文件,加入仓库
git add . //.表示全添加, git add README.md 表示只添加说明文件
//提交到仓库,这个版本名字叫
git commit -m "first commit"
按照以下格式提交到远程
git remote add origin git@github.com:yourgithubname/yourrepositoryname
git push -u origin master
如果出现错误,则是先删除那个东西,再提交就行了
git remote rm origin