Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Propagate a remote location via clone/push/pull

Our project uses several third-party open-source libraries, some of which require custom modifications.

For each library we created our own local git repository, added the original source location as a vendor remote, cloned from there, modified it as needed and pushed it to an internal remote repository (let's call it origin).

These repositories are then used as submodules in our core project.

The problem: The "vendor" remote url is not propagated to the "origin" and is therefore lost to anyone who clones the internal library repository.

Every time you want to merge the new upstream changes for a library, you need to find and manually add the vendor remote again (or use the exact same local repository created at the beginning, if it's still available).

Is there a better way to store the vendor repository url so that it can be propagated and used by every developer? Adding an extra file (e.g. clone_from_here) to the library doesn't seem very elegant, either.

like image 727
rluba Avatar asked Jan 03 '12 13:01

rluba


People also ask

How do I clone a remote repository?

To clone a Git repository, you will first copy the remote URL from your repository hosting service—in this case GitHub. You will then use the Git clone command followed by the remote repo's URL. If you are working with a private repository, you will be prompted for your remote hosting service credentials.

What is git push and pull?

git pull is one of many commands that claim the responsibility of 'syncing' remote content. The git remote command is used to specify what remote endpoints the syncing commands will operate on. The git push command is used to upload content to a remote repository.

What is the difference between pull and clone?

git pull is a (clone(download) + merge) operation and mostly used when you are working as teamwork. In other words, when you want the recent changes in that project, you can pull. The clone will setup additional remote-tracking branches.

Does git clone affect remote?

When we clone a repository, all the files are downloaded to the local machine but the remote git repository remains unchanged. Making changes and committing them to your local repository (cloned repository) will not affect the remote repository that you cloned in any way.


1 Answers

You can do it via .git/config. After you have successfully pulled or pushed your change, look at the .git/config file and make a note of the remote url and fetch

After the repository has been cloned by your developer(s), open up .git/config on the developers machine and add the line you have copied. Example -

[remote "vendor"]
    url = [email protected]:xxxxx/xxxxxxx.git
    fetch = +refs/heads/*:refs/remotes/origin/*

Your developers can now push or pull to vendor in this example.

If you need more control on writing the fetch url - there is excellent documentation on this at gitguys - http://goo.gl/JGaKD

like image 195
First Zero Avatar answered Nov 15 '22 07:11

First Zero