首先进入GitHub的官网,注册GitHub账户。
GitHub官网网址:https://github.com/
笔者已经注册了一个GitHub账号,且注册流程十分简单,所以不再赘述。笔者的GitHub主界面如下所示:
1.打开终端检查本地是否安装github,ubuntu默认是安装github的。
git --version
2.生成密钥对,此步骤如果遇见输入密码时,连续按回车键即可。
ssh-keygen -C "****@***.com" -f ~/.ssh/github #此处的邮箱是你的邮箱地址
3.查看公钥。
cat ~/.ssh/github.pub
4.登录github账号:
此时会出现如下界面:
将第3步中列出的公钥拷贝到上图的Key区域,Title任意。
5.检查本地是否能远程访问github服务器,出现You’ve successfully authenticated,说明认证通过。
ssh -T [email protected]
首先,清除所有的key-pair
ssh-add -D rm -r ~/.ssh
删除你在github中的public-key
重新生成ssh密钥对
ssh-keygen -t rsa -C "[email protected]" chmod 0700 ~/.ssh chmod 0600 ~/.ssh/id_rsa*
接下来正常操作
在github上添加公钥public-key:
1、首先在你的终端运行下方代码,将公钥内容复制到剪切板
xclip -sel c ~/.ssh/id_rsa.pub
2、在github上添加公钥时,直接复制即可
3、检查连接情况:
输入如下命令:
ssh -T [email protected]
Hi alioth310! You’ve successfully authenticated, but GitHub does not provide shell access.
即利用自己的用户名和email地址配置git
git config --global user.name "你的github用户名" git config --global user.email "你的github邮箱地址"
git clone https://github.com/你的github用户名/github仓库名.git
例如,添加一个新的文件
touch Readme_new
该步不可省略!(其实是提交到git缓存空间)
git add Readme_new git commit -m 'add new readme file'
首先,需要将本地仓库与github仓库关联
注:https://github.com/你的github用户名/你的github仓库.git 是github上仓库的网址
git remote add origin https://github.com/你的github用户名/你的github仓库.git
有时,会出现fatal: remote origin already exists.,那么,需要输入git remote rm origin 解决该问题
然后,push,此时,可能需要输入github账号和密码,按要求输入即可
git push origin master
注:有时,在执行git push origin master时,报错:error:failed to push som refs to…….,那么,可以执行
git pull origin master
至此,github上已有的仓库的便有了更新
如果需要添加文件夹,有一点需要注意:该文件夹不能为空!否则不能成功添加