Kris Anderson Kris Anderson - 1 year ago 101
Git Question

Start from GitHub repo, clone it privately in BitBucket, and also grab changes from the original?

I'd like to take an open source project available on GitHub and use it for a new website. Since it's going to be for private use, I plan on storing the code in BitBucket (since GitHub charges for private repos). But here's what I want to do.

  • I want to be able to pull from the origin (open source repo on GitHub) whenever I'd like and merge those changes into my project.

  • I'd like to be able to have my own copy that syncs with BitBucket privately that only I can access.

  • I'd like to be able to submit pull requests back to the origin on GitHub if I'm able to add any features or fix any bugs that I'm able to.

What's the best way to do that?

I'm thinking I can clone the repository locally, and make a branch of the master branch. I can then setup that new branch to sync to a BitBucket repository. At this point, the master branch will pull from the origin, and my branch will push/pull from my BitBucket branch. This way, I can do all of the work off my own branch, and when changes happen on the master, I can pull those and merge them back into my branch.

I think that would work, but that about my third point on what if I want to submit code to the open source project as a pull request? Wouldn't I need to have that code hosted in GitHub publicly? Is there a better way for me to do this?

Answer Source

I'd like to be able to submit pull requests back to the origin on GitHub

That means:

  1. fork that project on GitHub
  2. add a remote named upstream in order to fetch any new modifications from the original repo
  3. change the remote named origin for "fork" in order to reference your own fork on GitHUb
  4. add a remote named origin referencing your private BitBucket repo
  5. make your private modification in a dedicated branch.

That way, you are still being able to:

  • make pull request: simply push a dedicated branch to your "fork" remote, and do a pull request from that branch
  • make private modification that you would push to your BitBucket private repo
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download