1 将本地版本库添加到远程库
- 登录github,创建新的远程仓库
- 填写相关信息,可以选择公众库或是私人库
- 创建完如下,根据提示,我们应该按照提示进行第二部分的操作
就可以完成了
16921@LAPTOP-LRCLVB7E MINGW64 /d/git_res/yolo (master)
$ git remote add origin https://github.com/sysu18364010/yolo.git
16921@LAPTOP-LRCLVB7E MINGW64 /d/git_res/yolo (master)
$ git branch -M main
16921@LAPTOP-LRCLVB7E MINGW64 /d/git_res/yolo (main)
$ git push -u origin main
输出如下
Enumerating objects: 27, done.
Counting objects: 100% (27/27), done.
Delta compression using up to 8 threads
Compressing objects: 100% (27/27), done.
Writing objects: 100% (27/27), 12.31 MiB | 377.00 KiB/s, done.
Total 27 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (4/4), done.
To https://github.com/sysu18364010/yolo.git
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
可以看到这里出现了,branch的概念,后面讲解,现在登录github,查看一下!
2 远程库类型修改
不小心设置成了public库,不着急,点击setting->manage access
点击manage->change visibility就ok
3 从远程库克隆
3.1 公有库克隆
复制ssh
输入以下命令就可以完成了
$ git clone git@github.com:sysu18364010/clone_test.git
Cloning into 'clone_test'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
修改文件,再次上传
16921@LAPTOP-LRCLVB7E MINGW64 /d/self_intd/clone_test (main)
$ git add README.md
16921@LAPTOP-LRCLVB7E MINGW64 /d/self_intd/clone_test (main)
$ git commit -m "modify readme"
[main 7567547] modify readme
1 file changed, 4 insertions(+), 1 deletion(-)
16921@LAPTOP-LRCLVB7E MINGW64 /d/self_intd/clone_test (main)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 293 bytes | 97.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:sysu18364010/clone_test.git
0767720..7567547 main -> main
3.2 私人库克隆
私有库直接克隆会出现这个问题
$ git clone git@github.com:sysu18364010/self_intrd.git
Cloning into 'self_intrd'...
The authenticity of host 'github.com (140.82.113.4)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解决方法,在本地按照教程生成ssh key,在添加到git账号。参考这个教程2更详细。
新建一个文件夹,在这里的git bash里面输入
继续clone就行了。
后面会接着讲分支,以及具体利用git进行协作的例子