2.1 GitHub推送本地库到远程库
基本语法:git push 别名 分支
# 将master分支推送到别名为hellogit远程地址,
# 也就推送到https://github.com/abc/HelloGit.git(具体看前一节)
# 这里需要授权认证操作(输入账号密码)
abc@DESKTOP-R85C9HV MINGW64 ~/Desktop/HelloGit (master)
$ git push hellogit master
fatal: unable to access 'https://github.com/abc/HelloGit.git/': OpenSSL SSL_read: Connection was reset, errno 10054
abc@DESKTOP-R85C9HV MINGW64 ~/Desktop/HelloGit (master)
$ git push hellogit master
Enumerating objects: 13, done.
Counting objects: 100% (13/13), done.
Delta compression using up to 8 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (13/13), 1.02 KiB | 523.00 KiB/s, done.
Total 13 (delta 4), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (4/4), done.
To https://github.com/abc/HelloGit.git
* [new branch] master -> master
推送成功后,刷新GitHub账号即可。
凭据管理器可以删除已登录的github账号:
2.2 GitHub拉取远程库到本地库
基本语法:git push 别名 分支
在Github上修改hello.txt文件,并提交。
#从hellogit拉取到master分支上
abc@DESKTOP-R85C9HV MINGW64 ~/Desktop/HelloGit (master)
$ git pull hellogit master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 672 bytes | 168.00 KiB/s, done.
From https://github.com/JallenKwong/HelloGit
* branch master -> FETCH_HEAD
785ab46..47e257f master -> hellogit/master
Updating 785ab46..47e257f
Fast-forward
hello.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
2.3 GitHub克隆远程库到本地
基本语法:git clone 远程地址
clone 会做如下操作:
- 拉取代码。
- 初始化本地仓库。
- 创建别名。
在远程库获取地址URL
# 创建一个新文件夹
abc@DESKTOP-R85C9HV MINGW64 ~/Desktop
$ mkdir HelloGit-clone
abc@DESKTOP-R85C9HV MINGW64 ~/Desktop
$ cd HelloGit-clone/
# 在新的文件夹内,克隆远程库到本地
abc@DESKTOP-R85C9HV MINGW64 ~/Desktop/HelloGit-clone
$ git clone https://github.com/abc/HelloGit.git
Cloning into 'HelloGit'...
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 16 (delta 5), reused 12 (delta 4), pack-reused 0
Receiving objects: 100% (16/16), done.
Resolving deltas: 100% (5/5), done.
abc@DESKTOP-R85C9HV MINGW64 ~/Desktop/HelloGit-clone