比如主提交仓库使用的github 然后使用国内的一个托管仓库做备份。
那么如果不在本地设置分支的情况下,如何push代码到2个不同的托管仓库呢?
2个仓库的SSH Key我都配置好了。刚开始提交的时候使用git push 提交到主仓库,然后准备使用git push bak master 报错了。
后来看别人说可以在本地建立2个分支。感觉如果建分支 来回切换提交好繁琐。有木有其他更便捷的方法了?
你的意思是想把一个项目提交到两个远程仓库么?
是那样的话就添加两个远程仓库,然后分别push两次啊。
我的博客是备份到github和gitcafe 上 我是这样设置config的,每次commit后,git publish 就可以直接推送到两个仓库了。供你参考:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[remote "github"]
url = https://github.com/paddingme/paddingme.github.io.git
fetch = +refs/heads/*:refs/remotes/github/*
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "gitcafe"]
url = https://gitcafe.com/paddingme/paddingme.github.io.git
fetch = +refs/heads/*:refs/remotes/gitcafe/*
[alias]
publish=!sh -c \"git push github master && git push gitcafe master:gitcafe-pages\"
"刚开始提交的时候使用git push 提交到主仓库,然后准备使用git push bak master 报错了。"
什么错误?
bak 这个仓库远程仓库名字你写对了吗?能看一下你的 git remote -v 这个命令的结果吗?推送到两个仓库是很正常的需求,我一直都是这么做的,根本不需要两个分支,来回切换就是自找苦吃。