Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Fork / Remote / Clone Concepts

Tags:

git

github

I am trying to understand / visualize the elements that come with forking a repo. My starting reference is this help page.

1st Question:

When I forked a repo e.g. Spoon-Knife on GitHub (i.e. clicked the Fork button on their site), does it mean the Spoon-Knife is copied to my GitHub account? Did a real copy actually happen or is it just a concept?

2nd Question:

The next step in the help page is to do a clone:

$ git clone [email protected]:username/Spoon-Knife.git

This command made a copy of the source in my local machine. Did it clone from the forked / copied repo in my GitHub account (please see my first question)? Or, from the original Spoon-Knife repo?

3rd Question:

Step about configuring remotes:

When a repo is cloned, it has a default remote called origin that points to your fork on GitHub, not the original repo it was forked from. To keep track of the original repo, you need to add another remote named upstream.

So, is origin some kind of "proxy" between our local copy and the repo copy on my GitHub account? And, how about upstream?

Thanks beforehand for your help.

like image 913
moey Avatar asked Dec 12 '22 08:12

moey


1 Answers

  1. All you are doing when you "fork" is to effectively create a branch on their git repository that you can check into.

  2. Your local copy that you clone to is just cloned from and linked to the branch you created on git-hub. Remember a branch is just a pointer to a commit object, so when you "forked" you just added a branch name on their repo that points to the current head of their master.

  3. Remotes in git are just names to repositories at an external address. Your default "origin" is set up by git and is just a named remote. "upstream" is just another name and points to the original master that you originally branched from so that you can pull changes between master and your own branch. You can see your remotes with git remote -v and add them easily to track any branch on any externally available git repo.

like image 102
Mark Fisher Avatar answered Dec 28 '22 08:12

Mark Fisher