Clone Git repo so I can keep it updated with original, but keep my changes separate
Asked Answered
K

1

6

My apologies in advance for any misuse of git terminology...

I have an existing phpbb site. I would like to clone their repo, apply my changes, and create my own repo, in a way that way I can apply updates from the original phpbb master branch as they make them, and so I can maintain my own customizations. I'm just not entirely sure the order in which I should go about doing this. I'm not even sure if what I want to do is a fork?

What I want:

  • To be able to update my site from the phpbb master branch at my discretion.
  • To have my repo private (using bitbucket).

I know the files in their master branch that I'll need to change to make the site my own. So here's how I think it should work, though it probably won't because I never get this stuff right without asking for help first:

  • Clone phpbb to my local machine
  • Apply my current changes
  • Make a new repo on BitBucket
  • And here's where I'm confused - I know I need to do something with the remote/origin repos, but most guide available should you how to do a standard fork/pull or a clone - though I want my code to be possibly updated by the origin, but I never want to update their original code.

I have a dev, several test, and a prod machine, so I'd like an easier way to keep all this code up to date.

Keyway answered 3/1, 2016 at 8:56 Comment(1)
Possible duplicate of How to update a GitHub forked repository?Timbered
T
6

The usual thing to do is to keep two remotes: origin (your private fork) and upstream (the real one).

  1. Create your private fork and clone it (it will be empty)
  2. Add the "real one": git remote add upstream <url-of-the-real-one>
  3. Download upstream commits: git fetch upstream
  4. Force-apply upstream commits: git reset --hard upstream/master
  5. Now your local repository is no longer empty. Push the commits to origin: git push
  6. Apply your local edits, git commit them, and git push them

Now, if the upstream/master branch changes, you need to:

  1. Download again the updated commits: git fetch upstream
  2. Merge the upstream/master branch onto your local master branch: git merge upstream/master
  3. If step 2 generates conflicts you should resolve them
  4. Update your private fork: git push
Timbered answered 3/1, 2016 at 9:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.