git remote 讲解

介绍:

Remote 可以有几个,每一个通常是只读、只写或读/写,它可以理解为是远端代码托管平台的地址。Git 借助 remote 可以实现添加远程存储库、删除不再有效的远程存储库、管理各种远程分支并定义它们是否被跟踪等等。
仓库 remote 用于指向本地仓库在 codechina 托管的地址,目前比较常见的有 ssh 格式的,如:

git@gitlab.csdn.net:code-china/gitlab/codechina-workflow.git

http 格式,如:

https://gitlab.com/lsh0310/codechina-workflow.git

其中 http 格式中除上面案例中以外,codechina 还支持用户名密码格式以及 auth2 + access token 格式,如:

// 用户名密码
https://csdn-username:csdn-password@codechina.csdn.net/lsh0310/codechina-workflow.git 

// access token
https://oauth2:personal-accesstoken@codechina.csdn.net/lsh0310/codechina-workflow.git

注意:access token 可以在 codechina 的用户设置-访问令牌 中添加,必须有 API 以上访问权限才可以推送仓库代码。
在这里插入图片描述

在实际使用上,推荐采用 ssh remote ,其后续代码操作更为简单。

remote 管理:

新增一个 remote: git remote add <shortname> <url>
example:

git remote add origin1 https://codechina.csdn.net/lsh0310/codechina-workflow.git

删除一个 remote:git remote rm <shortname>
example:

git remote rm origin1

查看当前仓库的 remote:git remote -v
example:

origin1	https://codechina.csdn.net/lsh0310/codechina-workflow.git (fetch)
origin1	https://codechina.csdn.net/lsh0310/codechina-workflow.git (push)

origin2	git@gitlab.csdn.net:code-china/gitlab/codechina-workflow.git (fetch)
origin2	git@gitlab.csdn.net:code-china/gitlab/codechina-workflow.git (push)

origin3	https://oauth2:AGgaZ9SrZ2Qb8bNqJnUM@codechina.csdn.net/lsh0310/codechina-workflow.git (fetch)
origin3	https://oauth2:AGgaZ9SrZ2Qb8bNqJnUM@codechina.csdn.net/lsh0310/codechina-workflow.git (push)

origin4	https://lish:a03103498356@codechina.csdn.net/lsh0310/codechina-workflow.git (fetch)
origin4	https://lish:a03103498356@codechina.csdn.net/lsh0310/codechina-workflow.git (push)
异常处理:

向 codechina 平台推送代码时,提示“‘origin’ does not appear to be a git repository”时,有可能是仓库在 codechina 平台没有初始化,这时首先要确保仓库 remote 已经正确设置,然后使用 git push -u origin master 命令进行关联和代码推送。

好了,我们点击 这里,开始在 csdn codechina 平台上的第一个代码仓库吧

  • 7
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

李少辉-开发者

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值