重学Git-Git远程仓库管理

远程仓库

远程仓库就是存储项目代码文件的地方,由于认证方式的不同,远程仓库的链接可以分为两种:

给远程仓库(链接)起名字

再Git的实际使用过程中,如果每次提交给远程仓库都使用链接的话,那会显得很长,且当有多个仓库在管理时,就会显得很麻烦。所以Git提供了一个给远程仓库重新起个简单的名字的操作,也叫做创建远程仓库,其实就是将本地的某个名字与远程的某个仓库对应起来。

git remote add origin <REMOTE_URL>

其中 git remote add是标准命令,后面的origin指的是远程仓库的名字,随便指定,<REMOTE_URL>指的是远程的链接。

远程仓库名字修改

正常情况下,git push 会有两个参数,分别是远程连接名和分支名。如 git push origin main,意思就是将修改提交到远程连接名为origin的main分支。

origin是给某个远程仓库的链接指定一个名字,可以使用命令行修改远程连接的名字

$ git remote -v
# 查看现有远程
> origin  https://github.com/OWNER/REPOSITORY.git (fetch)
> origin  https://github.com/OWNER/REPOSITORY.git (push)

$ git remote rename origin destination
# 将远程名称从 'origin' 更改为 'destination'

$ git remote -v
# 验证远程的新名称
> destination  https://github.com/OWNER/REPOSITORY.git (fetch)
> destination  https://github.com/OWNER/REPOSITORY.git (push)

名字所对应的链接修改

origin所指定的远程链接也可以修改

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

同样可以使用以上命令将HTTP远程连接切换为SSH远程链接。

删除远程链接

当不需要使用当前的远程连接名字时,可以使用git remote rm <Origin Name>删除。
可见以下示例

$ 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)

注意,这只是删除了本地的一个链接映射,远程的服务器上的仓库不会受到影响。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值