本地新建GitHub远程仓库SSH连接,git init 及 clone的操作记录
2018-02-07 11:53
896 查看
背景
公司电脑更换,本人原来在Github上的代码需要继续使用Git来维护,以下内容为我操作时的记录20180207,方便自己学习,同时也希望为其他有同样问题的朋友提供一点思路。说明
## 表示注释说明必要的终端命令已经用颜色标记
重新新建ssh连接
## 打开终端 尝试连接gitlocalhost% ssh -T git@github.com
The authenticity of host 'github.com (192.30.255.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.
git@github.com: Permission denied (publickey).
## 首先,清除现电脑中所有的key-pair
ssh-add -D
rm -r ~/.ssh
## 删除你在github中的public-key
## 在浏览器中登录github --> settings --> SSH and GPG keys 中删除原来的
## 新建ssh-key 一般用你原先的邮箱账号
localhost% ssh-keygen -t rsa -C "zh75701@aidong.com"
## 连续3次enter键可以不要密码
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/aidong/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/aidong/.ssh/id_rsa.
Your public key has been saved in /Users/aidong/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:GXqSfUeT34v+3wW1AbfzJ28kEZNxc8wIhNIwQMhd3yQ zh75701.aidong@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| . +oo+oEo+o+Oo|
| o . .oo+ .=+*|
| ... = .+.|
| + o . o +=|
| + S . . =.=|
| o . . .*o|
| . .+|
| . .o|
| ...+|
+----[SHA256]-----+
## 刚刚生成文件的位置
localhost% cd ~/.ssh
localhost% ls
id_rsa id_rsa.pubknown_hosts
## vi 打开 id_rsa.pub 复制其中所有内容
localhost% vi id_rsa.pub
## 在浏览器中登录github --> settings --> SSH and GPG keys 中添加刚刚复制的 ssk key
## 再次尝试连接
localhost% ssh -T git@github.com
## 出现以下内容表示成功
Hi Sdfeidong! You've successfully authenticated, but GitHub does not provide shell access.
clone github账号下的已有项目
## cd 目标目录(ZJDTest)localhost% cd /Users/aidong/Desktop/Project/MyProject/GitHub/ZJDTest
localhost% git clone git://github.com/xxxxxx/ZJDKit.git
Cloning into 'ZJDKit'...
remote: Counting objects: 1396, done.
remote: Total 1396 (delta 0), reused 0 (delta 0), pack-reused 1396
Receiving objects: 100% (1396/1396), 6.47 MiB | 835.00 KiB/s, done.
Resolving deltas: 100% (514/514), done.
## 提交
## 打开项目修改后 cd 到目标目录
localhost% cd /Users/aidong/Desktop/Project/MyProject/GitHub/ZJDTest/ZJDKit
localhost% git add .
## 添加提交信息
localhost% git commit -m "测试clone项目提交"
[master e8d71b2] 测试clone项目提交
1 file changed, 1 insertion(+)
## 可以明显看出是修改了一个文件,新增了一行代码
## push提交
localhost% git push -u origin master
## 错误信息
fatal: remote error:
You can't push to git://github.com/xxxxxx/ZJDKit.git
Use https://github.com/xxxxxx/ZJDKit.git
## 添加 origin
localhost% git remote add origin https://github.com/xxxxxx/ZJDKit.git
fatal: remote origin already exists.
localhost% git remote rm origin
localhost% git remote add origin https://github.com/xxxxxx/ZJDKit.git
## 再次push提交
localhost% git push -u origin master
## 第一次会让提示输入 github的 账号
Username for 'https://github.com': xxxxxx
## github的 账号密码 终端无提示
Password for 'https://xxxxxx@github.com': 输入密码<终端无提示>
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 455 bytes | 227.00 KiB/s, done.
Total 5 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To https://github.com/Sdfeidong/ZJDKit.git
7a70772..e8d71b2 master -> master
Branch master set up to track remote branch master from origin.
## 至此提交成功了
## 以后再提交步骤
##
cd 目标目录
git add .
git commit -m "更新内容说明"
git push -u origin master
## 打标签可有可无
git tag 0.2.0
git push origin 0.2.0
## 完成
init github账号下的新建项目
## 先在github建一个空的项目,不再赘述## cd 到你需要用Git管理的文件夹下
cd 目标目录
git init
git add README.md
git commit -m "first commit"
## 添加源 就是你刚刚github上的空项目地址
git remote add origin https://github.com/xxxxxx/ZJDTest.git git push -u origin master
git tag 0.0.1
git push origin 0.0.1
## 完成
相关文章推荐
- 本地Git仓库与远程Github仓库的SSH连接配置
- Git 【基于SSH协议clone GitHub远端仓库到本地】
- SSH -- 建立本地GIT仓库和Github的连接
- Git 【基于SSH协议clone GitHub远端仓库到本地】
- Git 本地仓库与github远程连接
- Git 【基于SSH协议clone GitHub远端仓库到本地】
- Git命令操作远程仓库分支和本地仓库分支
- 项目管理---git----快速使用git笔记(五)------本地项目代码提交到远程仓库---新建项目
- git新建远程仓库时(所谓的中央仓库),要git init --bare 以防push之后还要reset
- 初探git 本地和远程仓库的操作
- 本地git和远程github连接完整教程
- 本地如何配置git环境连接远程代码仓库
- Git基础篇之远程仓库的基本操作以及如何给github的ReadMe文件添加图片
- GIT 如何合并另一个远程Git仓库的文件到本地仓库里某个指定子文件夹并不丢失远程提交记录
- 使用Git将本地仓库与GitHub远程仓库相关联
- 把本地文件上传到远程仓库:git和github,前提是上传的不能是空文件夹
- git 将本地文件推送到Github远程仓库
- Git 将本地新建的分支提交到远程仓库
- Linux之git常用命令详解 2017-04-12 20:09:40 分类: LINUX 1.从远程仓库下载代码到本地 #git clone http://gitlab.xxx.com/xxx.g
- Git本地仓库和github远程仓库