Search code examples
gitrepositorygit-clonegit-fork

GIT update forked project keeping my own changes


I'm new to GIT and I'm having a hard time trying to figure this out. I've search about this topic but everything I find isn't exactly related to my question.

Here's the thing: let's say there's repository online, that I fork (or clone, not sure if it makes any difference), and then locally I make my own changes to different files, add other files, remove some files, etc..

I don't want those changes to be pushed to the original repo. What I want is that if the original repo changes, I can update my fork/clone with those changes, and then apply my own changes again onto the updated vesion.

Everything I find online kind of talks about this, but always with the final goal of pushing the local changes to the original repository, so that doesn't work for me.

What would be the strategy to accomplish what I explained above?


Solution

  • Fork is the right approach: it clones the repo on the server side, allowing you to have your own copy (to which you can push to).

    This works for GitHub or BitBucket (which has also a fork)

    See Git fork is git clone?

    https://i.sstatic.net/yPKXU.png

    Once clone, updating your fork with updates from the original repo has to go through your local clone first.
    Meaning the update is done on your local repo and push to your fork (it cannot be done directly on your fork).

    That local clone can declare 2 remotes:

    • one called 'upstream', referring to the original repo
    • one called 'origin', referring to your online fork.

    The key is to fetch upstream, and rebase your local branch on top of upstream/master.
    See "Pull new updates from original Github repository into forked Github repository" for more.