Git Step by Step -- git remote

本文介绍如何通过Git命令管理远程仓库,包括查看、添加和更新远程仓库信息。具体操作包括使用.git/config文件查看配置,利用git remote命令列出远程仓库,通过git remote add设置新的远程仓库,以及使用git remote set-url更改远程仓库URL。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本地git项目的相关配置信息可以从 .git/config 文件中查看

[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
[remote "origin"]
	url = http://gitlab-tech.ikunchi.com/k2c/k2c-checkout.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
[branch "checkoutflow-dev"]
	remote = origin
	merge = refs/heads/checkoutflow-dev

remote  命令

1,git remote 不带参数,列出已经存在的远程仓库

KunChi@DESKTOP-NQNMVSS MINGW64 /d/kunchi-code/K2C/K2C-checkout (checkoutflow-dev)
$ git remote
origin

2,git remote -v | --verbose 列出远程仓库详细信息,在每一个名字后面列出其远程url

此时, -v 选项(译注:此为 –verbose 的简写,取首字母),显示对应的克隆地址:

KunChi@DESKTOP-NQNMVSS MINGW64 /d/kunchi-code/K2C/K2C-checkout (checkoutflow-dev)
$ git remote -v
origin  http://gitlab-tech.ikunchi.com/k2c/k2c-checkout.git (fetch)//表示从那个远程仓库fetch
origin  http://gitlab-tech.ikunchi.com/k2c/k2c-checkout.git (push) //表示向那个远程仓库push

3,git remote add [shortname] [url]:   将本地仓库关联到远程仓库地址

 shortname:远程仓库别名  默认为 origin

 url:远程仓库地址

添加远程仓库 要添加一个新的远程仓库,可以指定一个简单的名字,以便将来引用,运行 git remote add [shortname] [url]:

使用git init 新初始化的git 本地仓库  的.git/config 文件中没有  remote url 如下 

[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true

需使用该命令添加远程仓库   执行如下命令

$ git remote add origin http://gitlab-tech.ikunchi.com/k2c/k2c-checkout.git     

  .git/config 文件 改变

[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
[remote "origin"]
	url = http://gitlab-tech.ikunchi.com/k2c/k2c-checkout.git
	fetch = +refs/heads/*:refs/remotes/origin/*

 4  $ git remote set-url origin [url]  更改远程仓库指向

更改了远程仓库名称之后    使用该命令重新指向远程仓库

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值