一、查看所有远程仓库(必用)
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 别名 分支