背景
公司电脑更换,本人原来在Github上的代码需要继续使用Git来维护,以下内容为我操作时的记录20180207,方便自己学习,同时也希望为其他有同样问题的朋友提供一点思路。
说明
## 表示注释说明
必要的终端命令已经用颜色标记
重新新建ssh连接
## 打开终端 尝试连接git
localhost% ssh -T [email protected]
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.
[email protected]: 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 "[email protected]"
## 连续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
[email protected]
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.pub
known_hosts
## vi 打开 id_rsa.pub 复制其中所有内容
localhost%
vi id_rsa.pub
## 在浏览器中登录github --> settings --> SSH and GPG keys 中添加刚刚复制的 ssk key
## 再次尝试连接
localhost%
ssh -T [email protected]
## 出现以下内容表示成功
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://
[email protected]':
输入密码<终端无提示>
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
## 完成