3

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.

Christian Klauser
  • 4,416
  • 3
  • 31
  • 42

1 Answers1

2

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Ah didn't know about git dir templates, thanks :) This still requires 'external' documentation. My users need to know that they have to include a template when cloning. :( – Christian Klauser Jul 17 '14 at 07:11
  • 1
    @ChristianKlauser yes, to be clear, there wouldn't be a full automatic solution, but that is at least a workaround. – VonC Jul 17 '14 at 07:43