How to sync changes between a forked repo and its original on GitHub?

I’m working on a project where I forked a GitHub repo and made some changes. The original repo accepted my changes and added more stuff. Now I want to get those new changes into my fork without messing things up.

I tried doing a pull and then a push, but it ended up duplicating my commits. That’s not what I want. Is there a better way to keep my fork in sync with the original repo? I’m kind of new to this and could use some help figuring out the right steps.

Here’s what I’ve done so far:

git clone my-forked-repo
cd my-forked-repo
git add .
git commit -m "Made some changes"
git push origin main

After that, the original repo merged my stuff. Now I’m stuck on how to get their new changes without doubling up on commits. Any tips would be great!

I’ve been in a similar situation before, and here’s what worked for me:

First, make sure your local fork is up to date:

git fetch origin
git checkout main
git pull origin main

Then, add the original repo as a remote (if you haven’t already):

git remote add upstream https://github.com/original/repo.git

Now, fetch and merge the upstream changes:

git fetch upstream
git merge upstream/main

This should bring in all the new changes without duplicating commits. If there are conflicts, you’ll need to resolve them manually.

Finally, push the updated main branch to your fork:

git push origin main

This approach has always kept my fork in sync smoothly. Just remember to do this regularly to avoid falling too far behind the original repo.

hey Tom, sounds like u need to fetch upstream changes. try this:

git remote add upstream original-repo-url
git fetch upstream
git merge upstream/main

This’ll grab new stuff from original repo n merge it into ur fork. should avoid duplicate commits. lmk if u need more help!

To sync your fork with the original repo, you’ll want to use the ‘upstream’ remote. Here’s a streamlined process:

  1. Add the original repo as upstream:
    git remote add upstream https://github.com/original/repo.git

  2. Fetch upstream changes:
    git fetch upstream

  3. Ensure you’re on your main branch:
    git checkout main

  4. Merge upstream changes:
    git merge upstream/main

  5. Push to your fork:
    git push origin main

This method should bring in new changes without duplicating commits. It’s a good practice to do this regularly to keep your fork updated; if you encounter merge conflicts, you’ll need to resolve them manually before pushing.