# How to fetch a contribution branch to test it locally as an open-source maintainer

Hello Fellow CodeNewbies 👋,

In my [last post](https://adiati.com/git-how-to-fetch-a-branch-from-the-upstream-to-the-local-repo-in-5-steps), we talked about how to fetch a branch from `upstream` repo as a contributor and test it locally.

And in this post, let's change the role.  
If we were a repo maintainer, we would want to test the changes locally and see if things work as expected. Otherwise, we can encounter problems when we merge a contribution without trying it.  
How can we do so?  
I will walk you through the steps below.

## Fetch a contribution branch

### 1\. Add a remote repo for the forked repo

First, we need to add the contributor's forked repo as our remote repo.

```bash
git remote add <remote-name> <fork-repo-url>
```

We can name the `<remote-name>` anything we want. I find it clearer to name this remote with the contributor's name or their GitHub username.  
As an example:

```bash
git remote add ayu <fork-repo-url>
```

Go to the contributor's fork repo on GitHub to copy their repo URL and paste it to replace the `<fork-repo-url>` part.

### 2\. Check if the remote repo has been added.

Run this command to check our remote repos.

```bash
git remote -v
```

If the remote repo has been added, we should see:

```bash
origin <original-repo-url> (fetch)
origin <original-repo-url> (push)
ayu <fork-repo-url> (fetch)
ayu <fork-repo-url> (push)
```

### 3\. Fetch the forked repo to our local

Run this command to fetch the repo.

```bash
git fetch <remote-name>
```

So, in our case:

```bash
git fetch ayu
```

Now the repo contents, including the targeted branch, are fetched.  
We will see something like this on our command line:

```bash
...
* [new branch]      main           ->  ayu/main
* [new branch]      some-branch    ->  ayu/some-branch
* [new branch]      target-branch  ->  ayu/target-branch
```

But wait. There are three branches there.  
How do we know which branch is pushed by the contributor to the repo?

#### How to find out the pushed branch

1. On the original (`upstream`) repo on GitHub, navigate to the `Pull requests` tab.
    
2. Click on the contributor's pull request.
    
3. Under the title of the pull request, next to the green "Open" button, we will see:
    

```text
ayu wants to merge X commits into main from target-branch
```

We know now that the branch that we want to navigate to is the `target-branch`.

### 4\. Navigate to the branch

Run this command:

```bash
git checkout <branch-name>
```

In this example, it would be:

```bash
git checkout target-branch
```

We now can test out the changes from the contributor locally 😄.

---

Thank you for reading!  
Last but not least, you can find me on [Twitter](https://twitter.com/AdiatiAyu). Let's connect! 😊
