本机操作
1.打开终端输入指令
git --version
检查本地是否安装了git
如果没有,在终端输入sudo apt-get install git安装git
2.生成密钥对,此步骤如果遇见输入密码时,连续按回车即可。
ssh-keygen -C "****@***.com" -f ~/.ssh/github #此处的邮箱是你的邮箱地址
3.查看公钥
cat ~/.ssh/github.pub
4.登陆Github
点击右上角个人头像 --> 选择Settings --> 选择左侧对话框中的SSH and GPG keys --> 点击右上角New SSH key
此时会出现如下界面:
将第3步中列出的公钥拷贝到上图的Key区域,Title任意。
5.检查本地是否能远程访问github服务器,出现You’ve successfully authenticated,说明认证通过。
输入指令
ssh -T git@github.com
配置git
即利用自己的用户名和email地址配置git
git config --global user.name "你的github用户名"
git config --global user.email "你的github邮箱地址"
推送本地内容到Github上已有仓库
从github上将该仓库clone下来
git clone https://github.com/你的github用户名/github仓库名.git # 这里可以直接将仓库的HTTP复制过来
对clone下来的仓库进行更改,例如,添加一个新的文件
touch Readme_new
对刚刚的更改进行提交,该步不可省略!(其实是提交到git缓存空间)
git add Readme_new
git commit -m 'add new readme file'
push
首先,需要将本地仓库与github仓库关联(关联仅仅需要做一次就可以!!)
git remote add origin https://github.com/你的github用户名/你的github仓库.git # 这里可以直接将仓库的HTTP复制过来
有时,会出现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上已有的仓库的便有了更新。
如果需要添加文件夹,有一点需要注意:该文件夹不能为空!否则不能成功添加