A different way of reviewing pull requests
Tags: git, github, opensource
Published: 2021-10-08 00:32:11

## Introduction

When collaborating on an open-source project, you would often see beginners like myself relying on the GitHub website to review pull requests. However, the process was cumbersome, and I often wish there was a different way to see my partner's work and merge their pull requests without leaving the text editor. Luckily, Git does have a concept called Git Remotes, and in this blog, I will walk everyone through my journey of learning and using it.

## Adding support for a new feature

After looking through my classmates' projects, I decided to work on Minh Hang's static site generator and filed an issue to her [repo](https://github.com/minhhang107/mh-ssg/issues/10).

The objective was to add support for config files through the `-c` or `--config` flag. As both of us were using [yargs](https://github.com/yargs/yargs) to build the CLI, I could add a new argument by using the `option()` method:

```js
.option("config", {
    alias: "c",
    describe: "Specify config file",
    type: "array",
}
```

Additionally, I added an "if" statement to make sure that the tool will discard all other options when `-c` or `--c` is specified:

```js
if (argv.config) {
  const configPath = argv.config.join(" ");
  processJSONFile(configPath);
  return;
}
```

## Reviewing and testing my partner's work with `git remote`

To my understanding, a Git remote repository allows us to have a copy of the code on our local machine, and we can experiment on it without worry about affecting the original. Additionally, we can also get updates when there are changes by fetching. 

With that in mind, I began adding Hang's code as a remote to my local repo, carefully making sure that I'm not merging anything unnecessary by using `git fetch` instead of `git pull`:

```zsh
git remote add minhhang107 https://github.com/minhhang107/mini-ssg/tree/issue-12
git fetch minhhang107
```

I then created a new branch to track any additional commits, referencing the `issue-12` branch from my partner's [fork](https://github.com/minhhang107/mini-ssg/tree/issue-12):

```zsh
git checkout -b minhhang107-issue-12 minhhang107/issue-12
```

After setting up the remote branch, I began testing the implementation with the sample files/folder I made and providing feedback to my partner via Slack. With any additional changes/commits, I kept fetching them to the remote branch and continued testing until I could merge the working code to my `main` branch. 

## Conclusion

Git Remote is a handy feature that makes it easy for many developers to work on the same project. However, getting familiar with the command and understanding when to use them is quite a steep learning curve, as I often find myself going back to Git's documentation or my course's lecture. Hopefully, with enough practice, I can be more comfortable with using them.

Happy coding! 💻 

**Cover image by [Roman Synkevych](https://unsplash.com/@synkevych?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/git?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)**