DEV Community

Play Button Pause Button
Brian Douglas for GitHub

Posted on • Updated on

Sync Forks to Upstream Using GitHub Actions

Most challenging and severely under-documented in open source is how to keep your fork updated with the upstream.

There are a lot of unwritten rules in open source and inconsistencies between how projects approach contributions—your best chance for understanding that per project is the When I started contributing to open source, I always deleted my forks when my contribution merged; This can be tedious and overwhelming if you are working with many repositories.

Below is the workflow I leverage to keep bdougie/open-sauced-goals repo synced with the upstream.


name: Sync to Upstream

    - cron:  '12 7 * * 1,4'
    # scheduled at 07:12 every Monday and Thursday

    runs-on: ubuntu-latest
    name: Sync HEAD with upstream latest

    # Step 1: run a standard checkout action, provided by github
    - name: Checkout HEAD
      uses: actions/checkout@v2
        ref: main

    # Step 2: run this sync action - specify the upstream repo, upstream branch to sync with, and target sync branch
    - name: Pull upstream changes
      id: sync
      uses: bdougie/Fork-Sync-With-Upstream-action@fork
        upstream_repository: open-sauced/goals-template
        upstream_branch: main
        target_branch: main                       # optional
        github_token: ${{ secrets.GITHUB_TOKEN }}   # optional, for accessing repos that require authentication
Enter fullscreen mode Exit fullscreen mode

To make my action work, I forked an existing GitHub Action to add specific changes I needed. Consider checking out the original.

GitHub logo aormsby / Fork-Sync-With-Upstream-action

An action to automatically update your fork with new commits from the upstream repo

Also, consider checking opensource.guides for more information on how to contribute to open source.

This is part of my 28 days of Actions series. To get notified of more GitHub Action tips, follow the GitHub organization right here on Dev. Learn how to build action with Node.js

Top comments (1)

bdougieyo profile image
Brian Douglas

GitHub Actions now provides timestamps by default with "shift + T" in the logs.