Ryan Gannon
Ryan Gannon

Reputation: 61

How to pull from one Github repository to multiple local repositories?

I have a WordPress parent theme and multiple WordPress website (all on the same filesystem) that use it. So how do I make sure with Git that each instance of the parent theme is synced with the version on Github? Without having to pull each instance individually.

Upvotes: 2

Views: 559

Answers (2)

larsks
larsks

Reputation: 311318

You've asked how to keep multiple local repository clones up-to-date without having to pull each instance individually. Carl-Eric has addressed how to efficiently store multiple repositories on your filesystem. Here are some suggestions on keeping them up-to-date:

One solution would be to set up a post-merge hook in one of the repositories that iterates across the others and performs the pull operation:

#!/bin/sh

unset GIT_DIR
for repo in /path/to/repo1 /path/to/repo2; do
   ( cd $repo && git pull)
done

The post-merge script is run after a git pull operation.

Having said that, the simplest option would be to have a single clone of the repository and then symlink to it from the other locations.

Upvotes: 1

Carl-Eric Menzel
Carl-Eric Menzel

Reputation: 1266

First you clone the github repo once to your local machine.

Then you can continue in two ways:

  • you can simply do a local deep copy of that clone. All settings will be identical, the copies will all have their origin remote pointing to github. You will waste some disk space though, since all copies will obviously have the entire repo in them.
  • or, to save disk space, you can clone that local repo as often as you need. Git will try and reuse the repository objects as much as possible by hardlinking them. In this case you will likely have to adjust the remotes you're using, since origin will point to the local repository by default, rather than to Github.

Upvotes: 0

Related Questions