I'm curious if this is an everyday use case, but I need to sync a public repo to our internal GitHub Enterprise instance.
Forking is not an option because I'm going across domains and not within GitHub.com.
My purpose is to enable a GitHub Action internally.
I keep having to look up the steps, so here they are!
Destination Repository
First up, we create our destination repo. I'm going to retain the same name, or else I'll get confused; however, I'll drop the organization name.
Bare Clone
Next, we need to bare clone our source repo.
$ git clone --bare https://github.com/widdix/aws-cloudformation-github-deploy
Push Mirror
Next, we jump into that directory and push --mirror
to our new destination.
$ cd aws-cloudformation-github-deploy
$
$ git push --mirror https://git.local/ehnsw-actions/release-drafter.git
We no longer need our bare clone dir. I'll remove this to avoid confusion in the local filesystem.
Clone New Destination
Now we can jump into our new mirrored repo, so let's clone it.
$ git clone https://git.local/actions/aws-cloudformation-github-deploy.git
Upstream Remotes
Let's take a look at the existing remotes.
$ git remote -v
origin https://git.local/actions/aws-cloudformation-github-deploy.git (fetch)
origin https://git.local/actions/aws-cloudformation-github-deploy.git (push)
To pull upstream changes, we can add our upstream public repository but disable it so we can easily pull down updates with the following commands.
$ git remote add upstream https://github.com/widdix/aws-cloudformation-github-deploy.git
$ git remote set-url --push upstream DISABLE
This leaves us with the following settings
$ git remote -v
$ origin https://git.local/actions/aws-cloudformation-github-deploy.git (fetch)
$ origin https://git.local/actions/aws-cloudformation-github-deploy.git (push)
$ upstream https://github.com/widdix/aws-cloudformation-github-deploy.git (fetch)
$ upstream DISABLE (push)
Update from Upstream
When we want to sync updates from the public repository, we must perform the following commands.
$ git fetch upstream
$ git rebase upstream/master
$ git add *
$ git push
Create Releases
Finally, if the source repository uses releases, these need to be manually created in the GitHub Enterprise Instance.
Replicate the release name to the relevant tag or commit.
Summary
This post shows how to sync a public repo to a local git instance and pull down future updates.
I hope this helps someone else.
Cheers