多远程仓库 Git 完整命令手册


一、查看所有远程仓库(必用)

bash 复制代码
git remote -v

会显示所有远程仓库的别名和地址,例如:

复制代码
origin   https://github.com/xxx.git (fetch)
origin   https://github.com/xxx.git (push)
gitee    https://gitee.com/xxx.git (fetch)
gitee    https://gitee.com/xxx.git (push)

origin、gitee 就是远程仓库别名。


二、添加新的远程仓库

bash 复制代码
git remote add <别名> <仓库地址>

示例:

bash 复制代码
git remote add github https://github.com/xxx/test.git
git remote add gitee https://gitee.com/xxx/test.git
git remote add company http://git.company.com/xxx/test.git

三、指定远程仓库拉取代码 git pull

完整格式

bash 复制代码
git pull <远程别名> <分支名>

示例:

bash 复制代码
git pull github main
git pull gitee master
git pull company dev

四、指定远程仓库推送代码 git push

完整格式

bash 复制代码
git push <远程别名> <分支名>

示例:

bash 复制代码
git push github main
git push gitee master
git push company dev

首次推送 + 绑定上游(推荐)

以后可以直接简写 git push

bash 复制代码
git push -u github main
git push -u gitee master

五、修改远程仓库地址

bash 复制代码
git remote set-url <别名> <新地址>

示例:

bash 复制代码
git remote set-url origin https://xxx/new.git

六、重命名远程仓库别名

bash 复制代码
git remote rename <旧别名> <新别名>

示例:

bash 复制代码
git remote rename github github2

七、删除某个远程仓库

bash 复制代码
git remote remove <别名>

示例:

bash 复制代码
git remote remove gitee

八、一次性拉取所有远程代码

bash 复制代码
git fetch --all

九、一次性推送到所有远程仓库(超实用)

bash 复制代码
git remote | xargs -L1 git push

十、查看当前分支绑定的上游远程

bash 复制代码
git branch -vv

最常用多远程命令速查(直接背)

bash 复制代码
# 查看
git remote -v

# 添加
git remote add 别名 地址

# 拉取
git pull 别名 分支

# 推送
git push 别名 分支

# 首次推送绑定
git push -u 别名 分支

相关推荐
嘻嘻仙人15 小时前
Ubuntu中 git上传自己的项目和二次上传一般流程
git·github
Patrick_Wilson16 小时前
Squash Merge 的血缘陷阱:为什么删掉的代码又活了过来
前端·git·程序员
沉浸学习的匿名网友18 小时前
什么是 .gitignore?为什么每个 Git 项目几乎都离不开它?
前端·git
深海鱼在掘金2 天前
Git 完全指南 —— 第3章:理解工作区、暂存区、版本库三个核心
git
江华森2 天前
Git 基础筑基:从原理到团队协作的全栈实战
git
JakeJiang2 天前
Git 必备命令指南:从日常高频到项目开发实战
git
叫我少年3 天前
Windows 中安装 git
git
深海鱼在掘金8 天前
Git 完全指南 —— 第1章:Git 概览与版本控制演进
git
noravinsc9 天前
关于Git Flow
git
蜜獾云9 天前
在Git中配置用户名和密码
git