Git管理远程仓库

embedded/2024/10/9 9:20:36/

添加远程仓库

要新增远程,请在终端上存储存储库的目录中使用 git remote add 命令。

git remote add 命令采用两个参数:

  • 远程名称(例如 origin
  • 远程 URL(例如 https://github.com/OWNER/REPOSITORY.git

例如:

$ git remote add origin https://github.com/OWNER/REPOSITORY.git
# Set a new remote$ git remote -v
# Verify new remote
> origin  https://github.com/OWNER/REPOSITORY.git (fetch)
> origin  https://github.com/OWNER/REPOSITORY.git (push)

故障排除:远程原点已存在

此错误消息表示您尝试添加的远程与本地仓库中的远程名称相同。

$ git remote add origin https://github.com/octocat/Spoon-Knife.git
> fatal: remote origin already exists.

若要解决此问题,可以:

  • 对新远程使用不同的名称。
  • 在添加新的远程之前,重命名现有的远程仓库。
  • 在添加新的远程之前,删除现有的远程仓库。

更改远程仓库的 URL

git remote set-url 命令更改现有的远程存储库 URL。

git remote set-url 命令采用两个参数:

  • 现有远程仓库的名称。 例如,origin 或 upstream 是两个常见的选项。

  • 远程仓库的新 URL。 例如:

    • 如果您要更新为使用 HTTPS,您的 URL 可能如下所示:
    https://github.com/OWNER/REPOSITORY.git
    
    • 如果您要更新为使用 SSH,您的 URL 可能如下所示:
    git@github.com:OWNER/REPOSITORY.git
    

将远程 URL 从 SSH 切换到 HTTPS

  1. 打开Git Bash。

  2. 将当前工作目录更改为您的本地仓库。

  3. 列出现有远程仓库以获取要更改的远程仓库的名称。

    $ git remote -v
    > origin  git@github.com:OWNER/REPOSITORY.git (fetch)
    > origin  git@github.com:OWNER/REPOSITORY.git (push)
    
  4. 使用 git remote set-url 命令将远程 URL 从 SSH 更改为 HTTPS。

    git remote set-url origin https://github.com/OWNER/REPOSITORY.git
    
  5. 验证远程 URL 是否已更改。

    $ git remote -v
    # Verify new remote URL
    > origin  https://github.com/OWNER/REPOSITORY.git (fetch)
    > origin  https://github.com/OWNER/REPOSITORY.git (push)
    

将远程 URL 从 HTTPS 切换到 SSH

  1. 打开Git Bash。

  2. 将当前工作目录更改为您的本地仓库。

  3. 列出现有远程仓库以获取要更改的远程仓库的名称。

    $ git remote -v
    > origin  https://github.com/OWNER/REPOSITORY.git (fetch)
    > origin  https://github.com/OWNER/REPOSITORY.git (push)
    
  4. 使用 git remote set-url 命令将远程 URL 从 HTTPS 更改为 SSH。

    git remote set-url origin git@github.com:OWNER/REPOSITORY.git
    
  5. 验证远程 URL 是否已更改。

    $ git remote -v
    # Verify new remote URL
    > origin  git@github.com:OWNER/REPOSITORY.git (fetch)
    > origin  git@github.com:OWNER/REPOSITORY.git (push)
    

故障排除:没有该远程 '[name]'

此错误表示您尝试更改的远程不存在:

$ git remote set-url sofake https://github.com/octocat/Spoon-Knife
> fatal: No such remote 'sofake'

检查您是否正确键入了远程仓库的名称。

重命名远程仓库

使用 git remote rename 命令重命名现有远程。

git remote rename 命令采用两个参数:

  • 现有远程名称(例如 origin
  • 远程的新名称(例如 destination

重命名远程存储库的示例

这些示例假定使用 HTTPS 进行克隆(建议这样做)。

$ git remote -v
# View existing remotes
> origin  https://github.com/OWNER/REPOSITORY.git (fetch)
> origin  https://github.com/OWNER/REPOSITORY.git (push)$ git remote rename origin destination
# Change remote name from 'origin' to 'destination'$ git remote -v
# Verify remote's new name
> destination  https://github.com/OWNER/REPOSITORY.git (fetch)
> destination  https://github.com/OWNER/REPOSITORY.git (push)

故障排除:无法将配置部分 'remote.[old name]' 重命名为 'remote.[new name]'

此错误表示您键入的旧远程名称不存在。

可以使用 git remote -v 命令检查当前存在的远程:

$ git remote -v
# View existing remotes
> origin  https://github.com/OWNER/REPOSITORY.git (fetch)
> origin  https://github.com/OWNER/REPOSITORY.git (push)

故障排除:远程 [new name] 已存在

此错误表示您要使用的远程名称已经存在。 要解决此问题,使用不同的远程名称,或重命名原始远程。

删除远程仓库

使用 git remote rm 命令从存储库中删除远程 URL。

git remote rm 命令采用一个参数:

  • 远程名称(例如 destination

从存储库中删除远程 URL 只会取消本地和远程存储库的链接。 它不会删除远程存储库。

删除远程存储库的示例

这些示例假定使用 HTTPS 进行克隆(建议这样做)。

$ git remote -v
# View current remotes
> origin  https://github.com/OWNER/REPOSITORY.git (fetch)
> origin  https://github.com/OWNER/REPOSITORY.git (push)
> destination  https://github.com/FORKER/REPOSITORY.git (fetch)
> destination  https://github.com/FORKER/REPOSITORY.git (push)$ git remote rm destination
# Remove remote
$ git remote -v
# Verify it's gone
> origin  https://github.com/OWNER/REPOSITORY.git (fetch)
> origin  https://github.com/OWNER/REPOSITORY.git (push)

注意:git remote rm 不会从服务器中删除远程存储库。 它只是从本地存储库中删除远程及其引用。

故障排除:无法删除配置部分 'remote.[name]'

此错误表示您尝试删除的远程不存在:

$ git remote rm sofake
> error: Could not remove config section 'remote.sofake'

检查您是否正确键入了远程仓库的名称。


http://www.ppmy.cn/embedded/124995.html

相关文章

微知-一个不错的rpm大全网站,临时找rpm包的好地方(rpmfind.net)

背景 经常要安装某个rpm包,在默认的镜像源找不到。这个网站可以直接下载安装,能够部分解决问题。 有些场景下载后还有依赖包,不影响大环境的情况,可以以 -nodeps安装,然后尝试使用。 另外rpmfind.net网站能够work的本…

C++笔记之标准库和boost库中bind占位符_1的写法差异

C++笔记之标准库和boost库中bind占位符_1的写法差异 code review! 参考博文: C++新特性探究(十五):bind 在C++中,_1 和 std::placeholders::_1 都用于表示占位符,但它们有不同的上下文:

顺序表和链表的区别

顺序表和链表的区别 不同点顺序表链表(带头双向循环)存储空间物理上一定连续逻辑上连续物理上不一定连续随机访问(用下标随机访问)支持:O(1)不支持:O(N)任意位置插入或者删除元素可能需要搬移元素&#xf…

php对接中通SDK问题

记一次对接中通接口遇到的问题。 中通SDK是4年前的了,就这他们技术人员说能拉取的都是最新的,囧。 1.修改ZopHttpUtil.php中的请求方式 public function post($url, $headers, $querystring)//$timeout{$ch curl_init();curl_setopt($ch, CURLOPT_UR…

etcd 集群搭建【docker-compose】

文章目录 环境准备部署创建文件夹进入文件夹生成密钥启动查看集群成员查看节点状态结果 检查配置解说 环境准备 IPROLEETCD_NAME192.168.142.157masteretcd0192.168.142.156slaveetcd1192.168.142.155slave02etcd2192.168.142.158slave03etcd3 部署 创建文件夹 mkdir -p /d…

VNC轻松连接远程Linux桌面

Linux配置VNC(以RedHat、CentOS为例) 说明: Linux平台安装VNCServer Windows平台使用VNC-Viewer 1.在Linux平台安装VNCServer服务端软件包。 yum -y install vnc *vnc-server*2.修改VNCServer主配置文件 vi /etc/sysconfig/vncservers复制…

银河麒麟v10服务器操作系统ARM版下SPECjbb2015测试

ARM服务器进行SPEC jbb 2015测试 1 安装bisheng jdk 1.1 下载bisheng11.0.24,包括jdk开发包和jre运行环境,参见:毕昇JDK 1.2 安装bishengjdk,参见:毕昇JDK 11 安装指南 详细步骤如下: 1.2.1 在 Linux/AArc…

计算物理精解【9】-计算原理精解【6】

文章目录 马尔科夫链概述定义与性质分类应用领域收敛性马尔科夫链蒙特卡洛方法 马尔科夫链原理详解一、定义二、特性三、数学描述四、类型五、应用六、示例定义性质转移概率矩阵应用举例结论 马尔科夫链在语音识别和语音合成中的应用一、马尔科夫链在语音识别中的应用1. 基本概…