NotesUESTC/代码同步协作(Git)/Git高级操作-中fork的仓库同步主仓库.md

34 lines
905 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

1、查看远端仓库情况
```shell
git remote -v
# 样例输出如下:
origin http://logzhan.ticp.io:30000/logzhan/management.git (fetch)
origin http://logzhan.ticp.io:30000/logzhan/management.git (push)
```
2、将仓库添加到本地
执行完该命令,本地项目将同时关联到私有仓库与远程仓库地址。
```shell
# 命令参数upstream 表示远程仓库别名类似于origin
git remote add upstream 主库git地址
```
3、从主仓库更新代码
```shell
# 这句代码需要说明这句话表示我们要从upstream的main分支拉去代码到当前分支例如我们相把远端的A同步的本地的B
# 需要先git checkout B 然后 git fetch upsteram A
# 实际样例如下:
git fetch upstream main
```
4、推送到远程分支
```shell
# 此处的master是一个样例根据实际情况填写要合并的分支
git merge upstream/master
```