git remote

参考链接:

Git学习:git remote 命令 和 git push 命令-CSDN博客

远程仓库git remote详解_git remotes-CSDN博客

git remote 命令详解-CSDN博客

git remote 命令 | 菜鸟教程

1.介绍

      远程仓库是指存储在互联网或其他网络中的你的项目的版本库。远程仓库可以让你与其他开发者协作开发和共享代码,也可以作为你的代码的备份和发布的平台。

      git remote 命令用来创建、查看和删除本地仓库与远程仓库之间的连接。remote链接更像是一种书签标记而不是与远程仓库之间的硬连接。这种标记通过一种简单的命名来代替不便使用的完整URL,而不是提供一种与仓库之间的实时通道。

      为了让本地仓库知道要连接的远程仓库的位置,我们需要给远程仓库一个名称和一个URL。名称是一个标识符,用于在本地仓库中引用远程仓库。URL是指定了远程仓库的地址,可以是不同的协议,如SSH或HTTPS,具体取决于我们连接远程仓库的方式。我们可以使用git remote add 命令来添加远程仓库的名称和URL。将完整的URL设置为缩写名称,这样就可以使用缩略名表示远程仓库,而不需要每次都输入完整的URL。默认远程仓库名称为origin。

2.命令列表

命令 作用
git remote 列出当前仓库中已配置的远程仓库
git remote -v 列出当前仓库中已配置的远程仓库,并显示它们的 URL
git remote add 添加一个新的远程仓库。指定一个远程仓库的名称和 URL,将其添加到当前仓库中。
git remote rename 将已配置的远程仓库重命名
git remote remove 从当前仓库中删除指定的远程仓库
git remote set-url 修改指定远程仓库的 URL
git remote show 显示指定远程仓库的详细信息,包括 URL 和跟踪分支

3.实际使用

(base) claudius@claudius-vm:$ git remote -v
origin  [email protected]:chuchen/project_b.git (fetch)
origin  [email protected]:chuchen/project_b.git (push)
(base) claudius@claudius-vm:$ git remote add szgit [email protected]:chuchen/project_b.git
(base) claudius@claudius-vm:$ git remote
origin
szgit
(base) claudius@claudius-vm:$ git remote -v
origin  [email protected]:chuchen/project_b.git (fetch)
origin  [email protected]:chuchen/project_b.git (push)
szgit   [email protected]:chuchen/project_b.git (fetch)
szgit   [email protected]:chuchen/project_b.git (push)
(base) claudius@claudius-vm:$ git remote rename szgit shgit
(base) claudius@claudius-vm:$ git remote -v
origin  [email protected]:chuchen/project_b.git (fetch)
origin  [email protected]:chuchen/project_b.git (push)
shgit   [email protected]:chuchen/project_b.git (fetch)
shgit   [email protected]:chuchen/project_b.git (push)
(base) claudius@claudius-vm:$ git remote set-url shgit abcdefg
(base) claudius@claudius-vm:$ git remote -v
origin  [email protected]:chuchen/project_b.git (fetch)
origin  [email protected]:chuchen/project_b.git (push)
shgit   abcdefg (fetch)
shgit   abcdefg (push)
(base) claudius@claudius-vm:$ git remote show origin
* 远程 origin
  获取地址:[email protected]:chuchen/project_b.git
  推送地址:[email protected]:chuchen/project_b.git
  HEAD 分支:master
  远程分支:
    master 已跟踪
  为 'git pull' 配置的本地分支:
    master 与远程 master 合并
  为 'git push' 配置的本地引用:
    master 推送至 master (最新)
(base) claudius@claudius-vm:$ git remote remove shgit
(base) claudius@claudius-vm:$ git remote -v
origin  [email protected]:chuchen/project_b.git (fetch)
origin  [email protected]:chuchen/project_b.git (push)
(base) claudius@claudius-vm:$ 

4.本地仓库配置查看

文件位置:.git/config

说明:git remote add shgit 之后,本地仓库的配置文件新增了最下面框

git remote_第1张图片

你可能感兴趣的:(git)