newb question...tips for maintaining two similar repos

Hey All-

I’m fairly new to Github.  I have a public repo that has a bunch of code I been developing that will be part of an opensource robotics project.  We’ve cloned this repo to a new private repo for the next generation of the hardware, which will likely be closed source.  However when I make changes to the public repo is there a way to merge those changes automatically into the private repo?  Or is there a better way I could set this up so I’m not having to make all my updates manually to the cloned private repo if I patch bugs or add features in the public repo that I want in the private one?  Right now I’m just using wdiff and doing it by hand, but it’s getting tedious.  Tips?

thanks

-J

Hi @evilxsystems,

Welcome to the Github Community Forum!

If i’m not missunderstanding you can create a new remote repository in your local repository, with this you can push two times instead of copy and paste the code to the other local repository and push to the remote private repository.

To do this you need the remote command of git -> git-remote-docs

An example:

                  A—B---C—D     origin_public/master

                             II  

                   A—B---C—D     local/master

You have the remote repository and the local one. Now you want to add a new remote repository:

git remote add <name_of_new_remote> <link_of_remote>

if i called the new remote origin_private and the link is something like this https://github.com/user/private_repository.git:

git remote add origin_private https://github.com/user/private_repository.git

this command will create this history:

                  A—B---C—D     origin_public/master

                             II  

                   A—B---C—D     local/master

                             II  

                  A—B---C—D     origin_private/master

With this you can push changes in both repository with two push in sequence:

git push origin_public master
git push origin_private master

Or you can create a hook when you push to one of origin with hooks -> Git-Hooks with this feature you can create a pre-push hooks that do the other push, but i strongly dont reccomend it for many reasons.

Hope to solve your problem  :blush:

-Gabriele-

Mark helpfull posts with Accept as Solution to help other users locate important info. Don’t forget to give Kudos for great contents!

1 Like

This works when you have clean changes that will typically be integrated both ways. As the projects in this case will be diverging they will not be able to maintain that cleanly in an automated fashion as everything in git is a pointer and the pointers will not make sense in the completely different project. This could work for a while but its not sustainable long term in a purely automated fashion. When you make a private copy/fork of a repository you need to accept a certain level of maintenance involved in manually fixing merge conflicts and further manual integration when the projects have reached a certain level of divergence.

This is true, but…  If anything that is likely to changed is externalized (a separate source file in Java or C, or a separate module in Python, for example), then such conflicts can be minimized, possibly to the point of disappearing.

For example, create a directory and put Python code that varies between projects into that directory.  That directory becomes a git submodule that can be updated separately from the rest of the application.  The open source code uses a submodule which is the public repo and your private code uses a different submodule URL.

If you’re existing code base is large, this can be extremely painful to do, given the potential scope of the change.  But for small applicaitons that haven’t yet mushroomed (!), this can be quite effective.