DEV Community

Play Button Pause Button
Brian Douglas for GitHub

Posted on • Edited 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 CONTRIBUTING.md. 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.



// https://github.com/open-sauced/goals-template/blob/main/.github/workflows/sync-2-upstream.yml

name: Sync to Upstream

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

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

    steps:
    # Step 1: run a standard checkout action, provided by github
    - name: Checkout HEAD
      uses: actions/checkout@v2
      with:
        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
      with:
        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)

Collapse
 
bdougieyo profile image
Brian Douglas

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