Make your fork up-to-date with the master using a GitHub App. 🤖
Tags: github, git, opensource, tutorial
Published: 2020-07-23 14:20:41

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 isn’t 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](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/syncing-a-fork) 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](https://media.giphy.com/media/xTiTnvXly4hGvWqt6E/giphy.gif)
<figcaption>It's time to do the pull!</figcaption>

---

## [GitHub Apps](https://github.com/marketplace?type=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](https://developer.github.com/v3/) to access the data or to modify workflow files. If you're interested, take a look at [how to make your first GitHub App](https://docs.github.com/en/apps/building-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 🤖](https://probot.github.io/)

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](https://nodejs.org/), written in [TypeScript](https://www.typescriptlang.org/). It simply uses an internal event emitter to perform actions based on those events.

{% github probot/probot no-readme %}

#### [Pull 🤩](https://github.com/wei/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](https://github.com/apps/pull) and hit that big "Install" button.
After this, the app will automatically watch and pull in upstream's default (master) branch using [hard reset](https://git-scm.com/docs/git-reset#Documentation/git-reset.txt---hard) 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](https://docs.github.com/en/github/administering-a-repository/setting-the-default-branch) and then add a new file _pull.yml_ under the _.github_ folder. Here's a sample of changes you can do:

```yml
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
```    
This basically works as a [GitHub Action](https://docs.github.com/en/actions). If you're not sure what Actions are, then you can read my quick guide with tutorial:

{% link https://dev.to/vaibhavkhulbe/your-guide-to-github-actions-in-5-steps-41ma %}

After adding your settings, commit it and then go to this address: _https://pull.git.ci/check/${owner}/${repo}_.

Here, _${owner}_ means the owner username i.e if your GitHub profile URL is _[https://github.com/Kvaibhav01](https://github.com/Kvaibhav01)_, then your username is _Kvaibhav01_ and if repo URL is _[https://github.com/Kvaibhav01/Ripple-without-JS](https://github.com/Kvaibhav01/Ripple-without-JS)_, then _${repo}_ corresponds to _Ripple-without-JS_. Hence the above URL becomes:

_https://pull.git.ci/check/Kvaibhav01/Ripple-without-JS_ 

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 _https://pull.git.ci/process/${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](https://media.giphy.com/media/S6TEoUBJuGfQCoGl8l/giphy.gif)

---

_Thanks for reading, I appreciate it! Have a good day. (✿◕‿◕✿)_

---

<blockquote class="twitter-tweet" data-partner="tweetdeck"><p lang="en" dir="ltr">We&#39;re all friends here, right?<br><br>Image source: <a href="https://t.co/DHSf7uhG5O">https://t.co/DHSf7uhG5O</a><a href="https://twitter.com/hashtag/DevHumour?src=hash&amp;ref_src=twsrc%5Etfw">#DevHumour</a> <a href="https://twitter.com/hashtag/Frontend?src=hash&amp;ref_src=twsrc%5Etfw">#Frontend</a> <a href="https://twitter.com/hashtag/Backend?src=hash&amp;ref_src=twsrc%5Etfw">#Backend</a> <a href="https://twitter.com/hashtag/Programming?src=hash&amp;ref_src=twsrc%5Etfw">#Programming</a> <a href="https://t.co/NrFY4aE9aZ">pic.twitter.com/NrFY4aE9aZ</a></p>&mdash; Microsoft Developer UK (@msdevUK) <a href="https://twitter.com/msdevUK/status/1285541032176885762?ref_src=twsrc%5Etfw">July 21, 2020</a></blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

---

#### [📫 Subscribe to my weekly developer newsletter 📫](https://mailchi.mp/f59beeac6b9b/devupdates)

##### 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](https://medium.com/@vaibhavkhulbe)'s my Medium profile.