git远端仓库地址管理命令的使用方法

【原文链接】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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

redrose2100

您的鼓励是我最大的创作动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值