跳至主要內容

Git一次push到多个仓库

soulballad架构技术工具Git文字总结约 359 字大约 1 分钟

查看remote

git remote # origin
# 查看帮助
git remote -h

usage: git remote [-v | --verbose]
   or: git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>
   or: git remote rename <old> <new>
   or: git remote remove <name>
   or: git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
   or: git remote [-v | --verbose] show [-n] <name>
   or: git remote prune [-n | --dry-run] <name>
   or: git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
   or: git remote set-branches [--add] <name> <branch>...
   or: git remote get-url [--push] [--all] <name>
   or: git remote set-url [--push] <name> <newurl> [<oldurl>]
   or: git remote set-url --add <name> <newurl>
   or: git remote set-url --delete <name> <url>

    -v, --verbose         be verbose; must be placed before a subcommand

新增remote

git remote add <origin>
# git remote add gitee

设置remote 的url

# 设置gitee的url
git remote set-url gitee git@gitee.com:soulballad/spring-usage-examples.git
# 查看 remote
git remote -v
gitee   git@gitee.com:soulballad/spring-usage-examples.git (fetch)
gitee   git@gitee.com:soulballad/spring-usage-examples.git (push)
origin  git@github.com:Soulballad/spring-usage-examples.git (fetch)
origin  git@github.com:Soulballad/spring-usage-examples.git (push)

这种方式提交代码需要提交两次

git push origin master
git push gitee master

还有一种方式,只需要提交一次,就可以把代码push到不同仓库

# origin新增一个url
git remote set-url --add origin git@gitee.com:soulballad/spring-usage-examples.git
# 查看remote
git remote -v
origin  git@github.com:Soulballad/spring-usage-examples.git (fetch)
origin  git@github.com:Soulballad/spring-usage-examples.git (push)
origin  git@gitee.com:soulballad/spring-usage-examples.git (push)

只需要push一次,就可以提交两个仓库

代码强制提交

# git push <origin> <branch> --force
git push origin master --force
上次编辑于:
贡献者: soulballad