1、远程仓库分类
-
团队内使用,部署在内部服务器上的远程仓库。
-
公共的代码托管服务平台,GitHub、码云等。
2、远程仓库与本地仓库交互(同步)方式
-
所谓“同步”、“交互”,指的是“从远程仓库拉取代码到本地仓库”、“将本地仓库的代码上传至远程仓库”等操作。
-
目前公共的代码托管服务平台像 GitHub 等,常见的会提供 HTTPS、SSH 这两种形式的。SSH 方式需要进行简单的配置而 HTTPS 不需要,只要确保网络畅通即可。
2.1、SSH 方式配置
1、打开 Git Bash,任意路径下使用以下命令:
ssh-keygen
命令执行后,如果无特殊需求,直接默认配置,不断敲击回车即可

2、将生成的“公钥”配置到 GitHub 上

3、添加远程仓库
-
添加远程仓库即将已经建立好的本地仓库与远程仓库建立关联。
-
一个“本地仓库”可以与多个“远程仓库”进行关联。
-
添加远程仓库的常见方式:
a、先建立好“本地仓库”,使用git remote add
命令去添加“远程仓库”
b、直接“克隆远程仓库” -
先建立好“本地仓库”,在“本地仓库”路径下打开 Git Bash,使用
git remote add
命令去添加“远程仓库”
git remote add repo_name repo_address
repo_name
:可以理解称“远程仓库”名称,由于一个“本地仓库”可以与多个“远程仓库”相关联,所以可以使用这样的名称来区分。后续将本地代码推送至指定远程仓库时,需要使用该名称指定远程仓库。
当“本地仓库”只关联一个“远程仓库”时以及使用“克隆远程仓库”方式关联“远程仓库”,一般采用origin
命名。
repo_address
:从 GitHub 等网站上获取,可以选择使用 HTTPS 或 SSH 地址

4、查看本地仓库关联的远程仓库
git remote
git remote -v

5、推送本地仓库中的内容到远程仓库
- 推送前,确保已经完成本地仓库的提交,
git add
->git commit
git push -u repo_name repo_branch_name
例:git push -u origin master
git push repo_name repo_branch_name
例:git push origin master

6、从远程仓库获取最新内容

7、移除无效的远程仓库
- 解除本地与远程的关联

8、克隆远程仓库

9、解决冲突


网友评论