When Forking is not an option for your public git repos

When Forking is not an option for your public git repos

Table of Contents

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

Tags :
Share :

Related Posts

Github Runner ECS Authentication

Github Runner ECS Authentication

Using this fantastic open-source project, we have enabled github-actions using ephemeral self-managed runners on AWS SPOT.

Read More
Terraform, github-actions & OIDC on AWS

Terraform, github-actions & OIDC on AWS

I’ve posted here how to configure the OIDC AWS Provider & github Enterprise integration; however, nothing is better than an example of it working, and this post covers just that!

Read More
Fix github-actions 'Resource not accessible by integration' Error: Complete Guide

Fix github-actions 'Resource not accessible by integration' Error: Complete Guide

If you’re working with github-actions and encountering the “Resource not accessible by integration” error, you’re dealing with one of the most common github-actions permission issues. This error typically appears when your workflow lacks the necessary permissions to perform operations like creating pull requests, updating issues, or accessing repository resources.

Read More