DEV Community

Cover image for Make your fork up-to-date with the master using a GitHub App.
Vaibhav Khulbe
Vaibhav Khulbe

Posted on

Make your fork up-to-date with the master using a GitHub App.

You will accept the fact that whenever you're working on a team or individually with your buddy on a pet project which is open-sourced on GitHub, chances are when you come back after a few hours or days to check what others are up to, what they've contributed by the time you were doing other things, you're already frustrated.

Why? Because you've been doing this thing for quite long and repeatedly one day or the next. What you do is:

  • Check your forked repo to see the message "This branch is abc commits behind xyz:master".
  • Click on the Pull request option.
  • You find out that "There isnt anything to compare".
  • Then you click on "Try switching the base" to reveal that and yes, changes are needed!
  • You create a PR, and finally, merge it.

Well, all of the above 5 steps were done to simply update your fork with the master. And of course, you can do the same with command line as stated by GitHub if you prefer that method but you see, the bigger the project, the more number of collaborators, the more commits every hour, the more difficult it is to keep repeating those steps every now and then. There are many other options available in the market in form of tools, extensions or softwares which can do this for you if you set the configuration and whenever you want to update your fork, you press the "Sync" button to do the same.

What if we could automate this thing? Whenever the parent repo owner(s) merge someone's commit or adds a bunch of new files to the project, your fork automatically updates in the background without your slightest of intervention! No more PRs! Cool stuff right? Before we jump into the what and the how let's take a brief look GitHub Apps.

Pull GIF

It's time to do the pull!

GitHub Apps in the shortest way possible

The apps of GitHub are the integrations which are automated in order to improve the workflow of your collaboration on a project.

These apps communicate directly with the GitHub API to access the data or to modify workflow files. If you're interested, take a look at how to make your first GitHub App. The cool thing here is all of these can be installed directly on organizations/user accounts and granted access to specific repositories.

With that in mind, it's time to use one such App to automate our PRs.

The Probot and The Pull


Probot is your answer to the question, "Wouldn't it be cool if GitHub could do XYZ stuff..."

It's a complete framework to build GitHub Apps in Node.js, written in TypeScript. It simply uses an internal event emitter to perform actions based on those events.

GitHub logo probot / probot

A framework for building GitHub Apps to automate and improve your workflow

Pull 予

This is the lifesaver we were looking for!

Pull is a GitHub App which is built on top of Probot whose main function is (you guessed it...) to make your forks up-to-date with upstream via automated pull requests. Yay!

Sounds like heaven to me!

Sync your fork!

You can install Pull in two ways:

  1. Baby setup: If you're just starting out and don't need many configurations(s), just got to the Pull app listing and hit that big "Install" button.
    After this, the app will automatically watch and pull in upstream's default (master) branch using hard reset every couple of hours.

  2. Pro setup: This gives you control over the different types of rules, merging and label options. To start, make a new branch on your fork, then make this new branch as the default branch and then add a new file pull.yml under the .github folder. Here's a sample of changes you can do:

version: "1"
rules:                      # Array of rules
  - base: master            # Required. Target branch
    upstream: wei:master    # Required. Must be in the same fork network.
    mergeMethod: hardreset  # Optional, one of [none, merge, squash, rebase, hardreset], Default: none.
    mergeUnstable: false    # Optional, merge pull request even when the mergeable_state is not clean. Default: false
  - base: dev
    upstream: master        # Required. Can be a branch in the same forked repo.
    assignees:              # Optional
      - wei
    reviewers:              # Optional
      - wei
    conflictReviewers:      # Optional, on merge conflict assign a reviewer
      - wei
label: ":arrow_heading_down: pull"  # Optional
Enter fullscreen mode Exit fullscreen mode

This basically works as a GitHub Action. If you're not sure what Actions are, then you can read my quick guide with tutorial:

After adding your settings, commit it and then go to this address:${owner}/${repo}.

Here, ${owner} means the owner username i.e if your GitHub profile URL is, then your username is Kvaibhav01 and if repo URL is, then ${repo} corresponds to Ripple-without-JS. Hence the above URL becomes:

This is done in order to validate the pull.yml file. Finally, install the Pull app.

If you don't like automation, then you can still use Pull to trigger the update manually. For this go to${owner}/${repo} whenever you feel you need to update the fork.

All done!

Sit back, relax, and watch your fork updating automatically as you sip and enjoy the sunlight...

Relax GIF

Thanks for reading, I appreciate it! Have a good day. (踱踱)

We're all friends here, right?

Image source: #Frontend #Backend #Programming

Microsoft Developer UK (@msdevUK) July 21, 2020

Subscribe to my weekly developer newsletter

PS: From this year, I've decided to write here on DEV Community. Previously, I wrote on Medium. If anyone wants to take a look at my articles, here's my Medium profile.

Top comments (0)