3 easy steps to Auto Sync your Forked Repo with Upstream
Setting up a simple Github Actions Workflow
Have you ever wondered if there was a way to automate the exhausting process of keeping your forked repository in sync with the upstream repository? Apparently, there is, and it involves the usage of Github's own CI/CD platform GitHub Actions. It is a powerful platform that empowers your team to go from code to cloud, all from the comfort of your repositories.
In this post, I'll walk you through the process of setting up a new workflow for your forked repository.
In your forked repository, it is necessary that you make changes in a separate branch (a branch other than main) to keep the working tree clean and avoiding conflicts with upstream and also since it is considered best practice to do so. For a detailed explanation, check this.
Making sure you are on the other branch, go to the Actions tab of your forked repo.
Click on the setup a workflow yourself link
Now a window appears for you to edit the contents of your workflow's .yaml file. We are going to follow the Fork-Sync-With-Upstream-action from the Actions Marketplace.
Remove all the preexisting boilerplate stuff and paste the following code into the edit window.
on: schedule: - cron: '0 7 * * *' workflow_dispatch: jobs: sync_with_upstream: runs-on: ubuntu-latest name: Sync main with upstream latest steps: - name: Checkout main uses: actions/checkout@v2 with: ref: main - name: Pull (Fast-Forward) upstream changes id: sync uses: aormsby/Fork-Sync-With-Upstreamfirstname.lastname@example.org with: upstream_repository: ywalia01/artist-portfolio upstream_branch: main target_branch: main - name: Check for new commits if: steps.sync.outputs.has_new_commits run: echo "There were new commits." # Step 4: Print a helpful timestamp for your records (not required, just nice) - name: Timestamp run: date
You must edit the following attributes to suit your needs:
|upstream_branch||'master', 'main', 'dev'|
|target_branch||'master', 'main', 'prod'|
The cron attribute refers to the frequency at which you would prefer the action to auto-check if there are any new commits in the upstream repository. Currently it is set to trigger at 7:00 everyday. To customise the frequency refer to this.
After you're done editing the .yaml file, click on Start Commit and Commit new file and that's it!
Now head over to the Actions Tab once again and check to see if your workflow runs without any errors.
If you'd like to explore Actions from other Github users, here is a good collection of resources.