3

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?

Albert
  • 1,516
  • 3
  • 24
  • 55

1 Answers1

2

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.stack.imgur.com/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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thanks so much for the reply. I don't use github for now, I use bitbucket cause I work with private projects, but I assume the strategy should be the same. For what I understand, first I need to create a clone of the original project in my online repo, and then clone the "copy" into my local machine. Is that correct? – Albert Jul 19 '14 at 20:43
  • @Albert Everything works for BitBucket like GitHub: you can fork a repo on BitBucket and then clone it, like you could on GitHub. – VonC Jul 19 '14 at 20:44
  • @Albert So, first fork the repo (it is done on the GitHub or BitBicket side, I have included a link to the BitBucket documentation). Then clone that fork on your computer. Then add remotes to your local repo. – VonC Jul 19 '14 at 20:46
  • yeah I figured, and what about my previous comment? If that's correct, basically I would push the changes from my local clone to the online clone, and fetching any changes in the original project from the original repo, something like that, right? – Albert Jul 19 '14 at 20:46
  • @Albert That is indeed what I describe in http://stackoverflow.com/a/3903835/6309 – VonC Jul 19 '14 at 20:48
  • @Albert a good read on a similar topic (forking) is http://andrew.yurisich.com/work/2014/07/04/git-off-my-lawn/ – VonC Jul 19 '14 at 20:50