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

Ayu is a tech blogger, open source contributor & maintainer, and tech community enthusiast based in the Netherlands. She loves photography and iced coffee!
Search for a command to run...

Ayu is a tech blogger, open source contributor & maintainer, and tech community enthusiast based in the Netherlands. She loves photography and iced coffee!
No comments yet. Be the first to comment.
Hi friends ๐, I've been writing tech blog posts for a few years now. If you don't know me yet, English is my second language. My mother tongue is Indonesian, and I'm also surrounded by Dutch every da

I frequently receive messages from enthusiastic contributors who have completed 2 or 3 high-quality pull requests (PRs) in just 1 month. Theyโre proactive, their work is top-tier, and theyโve handled

A few months ago, I shared a story about building an automated open source portfolio using just my smartphone and an AI assistant while on vacation. My main goal was to stop the "spreadsheet struggle"

Recently, I read Bekah Hawrot Weigelโs blog post, "When 'Local' Went Global: The Pandemic Era of International Communities." As someone active in many online communities, I found it a bit sad, but I agree with her points and think they apply to open ...

Hacktoberfest is almost over. How has your contribution journey been so far? Are you confident about contributing to open source projects, or are you still struggling to find your way? If you're new to open source and still feel overwhelmed, that's c...

Hello Fellow CodeNewbies ๐,
In my last post, 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.
First, we need to add the contributor's forked repo as our remote repo.
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:
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.
Run this command to check our remote repos.
git remote -v
If the remote repo has been added, we should see:
origin <original-repo-url> (fetch)
origin <original-repo-url> (push)
ayu <fork-repo-url> (fetch)
ayu <fork-repo-url> (push)
Run this command to fetch the repo.
git fetch <remote-name>
So, in our case:
git fetch ayu
Now the repo contents, including the targeted branch, are fetched.
We will see something like this on our command line:
...
* [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?
On the original (upstream) repo on GitHub, navigate to the Pull requests tab.
Click on the contributor's pull request.
Under the title of the pull request, next to the green "Open" button, we will see:
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.
Run this command:
git checkout <branch-name>
In this example, it would be:
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. Let's connect! ๐