使用带有两个不同云的git分支同时维护私有和公共仓库 [英] Maintain a private and a public repo simultaneously using git branch with two different clouds

查看:79
本文介绍了使用带有两个不同云的git分支同时维护私有和公共仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是git的新手,并且在玩耍以了解更多信息.:)

First of all, I'm new to git, and playing around to learn more. :)

我将Github用于公共存储,将Bitbucket用于私有存储.每当我推送到github时,我都会手动切掉那些不需要的东西,然后将其公开推送,然后再次粘贴回那里,以维护私有仓库.

I'm using Github for my public repo, and Bitbucket for private repo. Whenever I push to github, I manually cut out those unwanted things and then push them publicly and then paste them back again there to maintain the private repo as well.

但是在学习了git branch之后,我认为可以通过多种方法来管理它,但实际上我不确定.我以为是

But after learning git branch, I thought there're many ways I can manage this, but actually I'm not sure. What I thought is:

  • 我将进行分支,将所有我的公开更改
  • 我将使用master进行所有私人更改(或者反之亦然)
  • 然后在私有"分支上,将 git remote add origin 设置为bitbucket repo HEAD,然后推送内容
  • 在公共"分支上,我将 git remote add origin 设置为github repo HEAD,然后推送内容
  • I'll make a branch will all my public changes
  • I'll use master with all my private changes (or it can be vice versa)
  • Then on "private" branch I'll set git remote add origin to bitbucket repo HEAD, and push things
  • and on "public" branch I'll set git remote add origin to github repo HEAD, and push things

我走对了吗?如果没有,那我该怎么走?

Am I on the right way? If not, how can I go then?

推荐答案

几乎.您可以添加两个遥控器,但是不能同时将它们都命名为origin.我只是将它们命名为github和bitbucket,但实际名称并不重要.然后,将适当的远程设置为本地分支的远程跟踪分支:

Almost. You could add two remotes but they cannot both be named origin. I'd just name them github and bitbucket but the actual names don't really matter. Then you set the appropriate remote as a remote tracking branch for your local branches:

git remote add github git@github.com:...
git remote add bitbucket git@bitbucket.com:...

git branch -u github/public_branch_name public_branch_name
git branch -u bitbucket/private_branch_name private_branch_name

# syntax is:
# git branch -u <remote>/<remote_branch_name> <local_branch_name>

在最后两个命令中,最后一个参数是您在本地调用的分支,倒数第二个参数包含在远程(斜杠后)调用的分支.这两个名称不必相同.您可以轻松完成

In the last two commands, the last argument is what you call your branch locally and the second to last argument contains what the branch is called on the remote (after the slash). Those two names do not have to be the same. You could easily do

git branch -u github/master public_branch_name
git branch -u bitbucket/master private_branch_name

看到您的存储库的人不会明智地发现还有其他东西.当然,您必须记住正在发生的事情.您可以使用 git branch --all -vv 检查哪个分支跟踪了什么.

and someone seeing your repositories would be none the wiser that there is something else. Of course, you have to keep in mind what's going on. You can check which branch tracks what with git branch --all -vv.

这篇关于使用带有两个不同云的git分支同时维护私有和公共仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆