Skip to content

Instantly share code, notes, and snippets.

@bdougie
Last active October 10, 2023 14:34
Show Gist options
  • Save bdougie/933771632e7e7fe8a4cc0ffa47e81812 to your computer and use it in GitHub Desktop.
Save bdougie/933771632e7e7fe8a4cc0ffa47e81812 to your computer and use it in GitHub Desktop.
name: Fetch Upstream
on: pull_request
jobs:
fetch-upstream:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: fetch and push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPSTREAM: https://github.com/babel/babel
run: |
git config --global user.name "github-actions"
git config --global user.email "github-actions@users.noreply.github.com"
# inspired by https://dev.to/ranewallin/how-to-keep-your-forked-repository-current-38mn
# If you haven't already added an upstream source, set your upstream
# to the fork's original source
git remote add upstream "${UPSTREAM}"
# Remote with access for pushing
git remote add fork "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
# Verify upstream is correct, you should see the URL for the upstream fetch and push
git remote -v
# Get all recent branches and commits from the upstream
git fetch upstream
# Merge the branches and commits from the upstream
git merge upstream/master
# helpful for debugging
git show-ref
# Set upstream branch and push to the forked remote repo
git checkout -b upstream
git push -u fork upstream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment