Git: plug / remote / clone concepts

I am trying to understand / visualize the elements that come with a forking repo. My start link is a man page .

1st question :

When I branched a repo, for example. Spoon-Knife on GitHub (i.e. I clicked the β€œPlug” button on my website), does this mean that Spoon-Knife is copied to my GitHub account? Did the real copy really happen or is it just a concept?

Second question :

The next step on the help page is to make a clone:

$ git clone git @ github.com: username / Spoon -Knife.git

This command made a copy of the source on my local machine. Was it cloned from a forked / copied repo in my GitHub account (see My first question)? Or starting with the original Spoon-Knife repo?

The third question :

Step about setting up remotes:

When cloning a repo, it has a remote origin by default, which points to your fork on GitHub, and not the original repo from which it was forked. To track the original repo, you need to add another remote called upstream .

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

Thanks in advance for your help.

+4
source share
6 answers
  • Everything that you do when "fork" effectively creates a branch in your git repository, which you can check.

  • Your local copy you are cloning to is just cloned and linked to a branch created on git-hub. Remember that a branch is just a pointer to a commit object, so when you fork, you simply add the branch name to your repo, which points to the current head of your master.

  • Remotes in git are just names for repositories at an external address. Your "source" is configured by default on git and is only named remote. "upstream" is just another name and points to the original master from which you originally forked so that you can transfer the changes between the master and your own branch. You can see your remote controls with git remote -v and easily add them to track any branch on any git repository accessible from outside.

+4
source

You need to distinguish between fork and clone.

  • clone is a Git concept that existed before GitHub: when you clone a repository, you copy the entire history and data into it into your newly created repository. In addition, the deleted file is automatically created in a new repository called origin , which points to the cloned repository.

  • fork is a GitHub concept that the Git kernel is not aware of. When you develop a GitHub project, you create your own GitHub project, which is identical to the original, and all GitHub features, such as the fork diagram, are automatically updated. Behind the scenes, the fork also includes cloning the Git repository in the source project and creating a new Git repository in your newly created project.

If you want to work on a GitHub project from your own private machine, you need to first clone this repository, whether it is your repository or someone else. If you clone your GitHub project, you will get it as an origin , but if you want the original project also to be deleted, you need to add it manually (and call it upstream , for example).

+4
source

1st question:

You copied it. This is actually a kind of clone. Now you have a copy of the project (actually one of its branches) in your github account.

Second question:

The clone git command clones the repo you give it. So $ git clone git@github.com :username/Spoon-Knife.git clone Spoon-Knife from the username repo. If this is your account, then this is a copy of your copy of the Spoon-Knife repository :)

Third question:

origin not a proxy, it is just a name for another repo. For example, the following command adds a repo named local_srv :

 git remote add local_srv /path/to/local/srv 

upstream is another remote. You can configure it to extract from it (i.e. get updates).

In your case, origin is your github repo (I call remote github ), and you can add upstream remote to the original Spoon-Knife repository. Therefore, you work in your project in local mode, click on your github account (for example, git push origin master ) and get new updates to the Spoon-Knife project using git pull upstream master .

Note: here I used only the master, but you can replace it with the branch you like.

+2
source

When I branched a repo, for example. GitHub Spoon Knife, does this mean that the Spoon Knife is copied to my GitHub account?

Yes.

Did the real copy really happen or is it just a concept?

This is the implementation details at the end of Github. It doesn't matter to you. (I'm sure they share the repository).

Was it cloned from a forked / copied repo in my GitHub account? Or starting with the original Spoon-Knife repository

Since you pointed it to your account in your account, it will be copied from there. However, the contents of the two forks are identical at this point.

So, is there some kind of β€œproxy” between our local copy and the repo copy on my GitHub account? And what about upstream?

Not really. "origin" is just a repository identifier on GitHub to make it easier for you to communicate with it. upstream will work the same. You do not need to configure these remotes, but having them for all repositories you often work with (push or pull changes) makes it easier for you to work. The names "origin" and "upstream" are also just conventions (you should follow), there is no "magic" for them.

+1
source

With git, each repository gets the full story. In fact (with the exception of some data-sharing optimization between the local repository), each repository is a clone of another repository. Or in git the hub says the plug (they are one and the same).

So, you have three repositories: the original repository for developers, a clone in the git hub (they call it fork) and a local clone of this clone. The name origin is just an abbreviation for referring to your repository on the git hub (your first clone). Without this shorthand, you would need to provide a complete URI to the repository at every step.

A repository can have many such abbreviated names in another repository. It is recommended that they all be cloned from the same original repository, so that the story is a simple directed acyclic graph with one root.

You could work without an intermediate clone on the git hub, but since you do not have write access to the original developer repository, and access to your private repository may be impractical for you, this git repository can be used as a communication gateway for the patch between you and the original author.

+1
source

3 repositories

 original - {GitHub}/octocat/Spoon-Knife forked - {GitHub}/ mine/Spoon-Knife local - {local} /Spoon-Knife 
  • When you are a β€œplug,” you have an actual copy in the sense that you have read / write access to it. However, it's best to think about how to efficiently create a branch in the original git repository, which you can write to. "

  • The fork action copied the original to your GitHub account. You can directly click from local clone to forked (NOT original ).

  • Simply put, remote is the name in the repository at an external address.
    "origin" - indicates forked ("origin" is the default name remote )
    upstream - points to original so you can get changes in your repositories

You can see your remote controls with git remote -v and easily add them to track any branch on any git repository accessible from outside.

Partially obtained from a response from Mark.

+1
source

Source: https://habr.com/ru/post/1380897/


All Articles