Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do git remotes work?

If I have a main project that is version controlled.

I then add a remote for a third party plugin

git remote add myplugin <url>

I can then do git pull myplugin master

and it just pulls in the changes from that remote.

Now lets say my project is setup as:

/
/index.php
/whatever

and the remote is setup as

/
/whatever.php

when I pull in the remote I end up with

/index.php
/whatever
/myplugin
/myplugin/whatever.php

this is good.

What I am wondering is, If I make changes to myplugin,

If I issue git push myplugin master what is pushed?

Is it going to only push changes in myplugin? or does a remote act as a second repository and will commit the entire repository?

like image 714
Hailwood Avatar asked Sep 13 '12 05:09

Hailwood


1 Answers

You would end up, after a git pull myplugin, in /myplugin/whatever.php only if the remote repo already contained /myplugin/whatever.php (not juut whatever.php)

Adding a remote means pulling all its history and merging it into your repo, or pushing your commits from all your repo into the remote (not just the changes from your local 'myplugin').

What you are describing (pushing only the changes from 'myplugin', or pulling commits only in 'myplugin') is called submodules.

 git submodule add url/myplugin myplugin

That would add a directory myplugin, in which you would find a second nested Git repo acting like you describe in your question.
It isn't just a new remote, but a submodule url for including in a subdirectory another repo at a specific SHA1.

like image 53
VonC Avatar answered Sep 19 '22 23:09

VonC