14. git remote

基本概述

git remote 的作用是:查看、添加、修改和删除与本地仓库关联的远程仓库。

基本用法

1.查看远程仓库

git remote                    # 显示所有关联的远程仓库(名称)
git remote -v                 # 显示所有关联的远程仓库(名称 + URL)
git remote show <远程仓库名>    # 查看特定远程仓库的详细信息

2.添加远程仓库

git remote add <远程仓库名> <仓库URL>
# 示例(添加 GitHub 仓库):
git remote add origin https://github.com/user/repo.git

3.删除远程仓库

git remote remove <远程仓库名>
# 示例:
git remote remove origin

4.重命名远程仓库

git remote rename <旧名称> <新名称>
# 示例(将 origin 改为 upstream):
git remote rename origin upstream

5.修改远程仓库URL

git remote set-url <远程仓库名> <新URL>
# 示例(切换 HTTPS 到 SSH):
git remote set-url origin [email protected]:user/repo.git

你可能感兴趣的:(Git,git)