Git----Git远端仓库地址管理命令应用
  TEZNKK3IfmPf 2023年11月14日 30 0
git

 

一、应用场景:

将主仓代码同步到个人的代码仓,以开源github上pytest代码为例,比如开源git地址为 git@github.com:pytest-dev/pytest.git,fork到个人仓git地址为:git@github.com:redrose2100/pytest.git

(1)在本地初始化一个pytest的代码仓,因为还没有和远端代码仓关联,因此这里看不到什么关联关系,git remote -v 即为查看本地仓库和远端仓库的关联关系的

hitre@iscas-redrose2100 MINGW64 /d/src/pytest
$ git init
Initialized empty Git repository in D:/src/pytest/.git/

hitre@iscas-redrose2100 MINGW64 /d/src/pytest (master)
$ git remote -v

hitre@iscas-redrose2100 MINGW64 /d/src/pytest (master)
$

(2)将本地仓库和远端个人仓和公共代码仓关联,个人仓远端地址名为origin,公共代码仓地址名为upstream,这是通用的名称,当存在更多远端代码仓时,还可以自己定义远端代码仓比如gitee

hitre@iscas-redrose2100 MINGW64 /d/src/pytest
$ git init
Initialized empty Git repository in D:/src/pytest/.git/

hitre@iscas-redrose2100 MINGW64 /d/src/pytest (master)
$ git remote -v

hitre@iscas-redrose2100 MINGW64 /d/src/pytest (master)
$ git remote add origin git@github.com:redrose2100/pytest.git

hitre@iscas-redrose2100 MINGW64 /d/src/pytest (master)
$ git remote -v
origin  git@github.com:redrose2100/pytest.git (fetch)
origin  git@github.com:redrose2100/pytest.git (push)

hitre@iscas-redrose2100 MINGW64 /d/src/pytest (master)
$ git remote add upstream git@github.com:pytest-dev/pytest.git

hitre@iscas-redrose2100 MINGW64 /d/src/pytest (master)
$ git remote -v
origin  git@github.com:redrose2100/pytest.git (fetch)
origin  git@github.com:redrose2100/pytest.git (push)
upstream        git@github.com:pytest-dev/pytest.git (fetch)
upstream        git@github.com:pytest-dev/pytest.git (push)

hitre@iscas-redrose2100 MINGW64 /d/src/pytest (master)
$ git remote add gitee git@gitee.com:redrose2100/pytest.git

hitre@iscas-redrose2100 MINGW64 /d/src/pytest (master)
$ git remote -v
gitee   git@gitee.com:redrose2100/pytest.git (fetch)
gitee   git@gitee.com:redrose2100/pytest.git (push)
origin  git@github.com:redrose2100/pytest.git (fetch)
origin  git@github.com:redrose2100/pytest.git (push)
upstream        git@github.com:pytest-dev/pytest.git (fetch)
upstream        git@github.com:pytest-dev/pytest.git (push)

hitre@iscas-redrose2100 MINGW64 /d/src/pytest (master)
$

(3) 代码同步:首先本地切换到通远端同一个名称的分支名,然后从origin分支拉取代码,这里我们指导upstream是官方的代码,因此,需要从uptream拉取官方代码,然后合入到本地分支,再从本地分支推送到origin个人远端仓和gitee码云平台的远端仓,这样就做到了github个人代码仓和gitee代码仓通github上官方代码仓代码同步了

git checkout -b main

git pull origin main

git fetch upstream

git merge upstream/maiin

git push origin main

git push gitee main

(4)修改和删除远端分支

git remote set-url origin xxxxx   # 将origin远端的url修改为xxxxx
git remote rm origin    # 删除origin远端的url
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月14日 0

暂无评论

推荐阅读
  TEZNKK3IfmPf   2024年04月12日   54   0   0 命令git
  TEZNKK3IfmPf   2024年04月19日   65   0   0 git部署
  TEZNKK3IfmPf   2024年04月26日   40   0   0 gitgithub
TEZNKK3IfmPf