Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set up more than one 'automatic' remote when cloning git repo

Tags:

git

clone

fork

I would like to clone ('fork') a public git repository (residing, say, on GitHub) to our internal network in such a way that whenever a developer clones that forked repository, they automatically get two remotes in their local repository:

  • origin (pointing to our internal, forked repository)
  • upstream (pointing to the original, public repository)

Example

Say we have a public repository at https://github.com/someone/foo.git

I'd now like to have a clone on our internal network at internal-repos:foo.git.

When the developer clones that repository git clone internal-repos:foo.git, they should have two remotes in their working copy

  • origin pointing to internal-repos:foo.git
  • upstream pointing to github.com/someone/foo.git

Is that possible? If so, how can I do that? AFACT git remote only operates on the local configuration.

like image 405
Christian Klauser Avatar asked Dec 19 '25 01:12

Christian Klauser


1 Answers

You could try and add a post-checkout hook which would be triggered on a git clone.

That could be possible through the (shared and accessible by all) template folder, as described in "git-clone and post-checkout hook"

See the Template section of the git init command: a git clone --template=/a/shared/folder could declare such a hook, which would then be in the cloned repo, and could add the missing remote.

like image 105
VonC Avatar answered Dec 20 '25 18:12

VonC