0

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

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.

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:

  • 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?

Mayeenul Islam
  • 4,532
  • 5
  • 49
  • 102

1 Answers1

3

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

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.

musiKk
  • 14,751
  • 4
  • 55
  • 82