git 连接仓库
1.使用环境
centos6
2.连接步骤
步骤一:在用户主目录(我是root用户,所以目录为 /root)下生成本机密钥,命令如下
#ssh-keygen -t rsa -C "你的邮箱地址"
//1.命令有交互的地方直接回车就可以
//2.生成的密钥位于 用户主目录/.ssh/
// 3.该目录下有两个文件id_rsa,id_rsa.pub
步骤二:复制id_rsa.pub的文件内容,
进入 https://github.com/,右上角 登录(sign in )账户,登录后 右上角会有你的头像,找到settings,如下图
步骤三:进入后,左边选择 SSH and GPG keys , new 一个SSH ,
标题 随意,将id_rsa.pub的内容 粘贴到 key这一栏中
步骤四:连接远程仓库( 远程库的名字叫 origin ) 在
本地仓库下执行 ,我的github上的项目名字为learn2
#git remote add origin
git@github.com/你的账户名/learn2.git
步骤四:推送,将本地仓库内容推送至云端
#git push -u origin master
若出现报错:
error: The requested URL returned error: 403 Forbidden while accessing
fatal: 'git@github.com/GCS85/learn2' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
解决方案:
在本地仓库的文件夹下
#vim .git/config
进入之后将
[remote "origin"]
url = git@github.com/你的账户名/learngit.git
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com/你的账户名/learngit.git
fetch = +refs/heads/*:refs/remotes/origin/*
修改为:
[remote "origin"]
url = ssh://git@github.com/你的账户名/learngit.git
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://git@github.com/你的账户名/learngit.git
fetch = +refs/heads/*:refs/remotes/origin/*
保存退出vim
再次执行步骤四,在github网站进行验证,是否本地文件上传成功
1181

被折叠的 条评论
为什么被折叠?



