At Tighten, we do lots of open source work. We even have a whole day every week devoted to it. And, thankfully, we have many members of the open source community contributing pull requests to our projects and packages.
But occasionally we have a pull request that needs one tiny fix: an updated Travis config file, a small adjustment to the
composer.json version constraints, or a typo in the readme. We could review the pull request and ask for those changes, and that's often our strategy on internal projects.
Isn't there an easier way? Can't you just add your own commits to someone else's pull request?
Yes. And it's very easy.
In our example, you are Ford Prefect. You're working on the latest edition of the Hitchhiker's Guide to the Galaxy in the repo
fordprefect/the-guide. A wonderful open source contributor Arthur (
arthurdent) forks your repo and makes a pull request.
Arthur's pull request looks great, but he misspelled "towel" in one section as "tolwe." Open source contributors are great, but what if he doesn't ever come back to this pull request? Instead of asking him to fix it, you want to quickly push a fix yourself.
If you haven't already, clone your own repo locally.
git clone firstname.lastname@example.org:fordprefect/the-guide.git
In order to see the other user’s fork (and push commits to it), you'll add their fork as a remote to your local repo.
git remote add arthurdent email@example.com:arthurdent/the-guide.git
You should now see the fork as a new remote, called
arthurdent, when you run
git remote -v:
sites/git/the-guide on main ➜ git remote -vorigin firstname.lastname@example.org:fordprefect/the-guide.git (fetch)origin email@example.com:fordprefect/the-guide.git (push)arthurdent firstname.lastname@example.org:arthurdent/the-guide.git (fetch)arthurdent email@example.com:arthurdent/the-guide.git (push)
git fetch arthurdent
You'll need to check out the branch they used for the pull request. If you're not sure what branch they used, look on the top of the pull request (e.g.,
arthurdent:main). Name it something other than
main locally so there's no conflict with your own
git checkout -b arthurdent-main arthurdent/main
Make your changes locally, commit, then push to their remote’s head.
git commit -am "Fix how you spelt towel"git push arthurdent HEAD:main
That's it! If all goes well, you'll see this commit show up at the bottom of the pull request.
! [remote rejected] HEAD -> main (permission denied)error: failed to push some refs to 'firstname.lastname@example.org:arthurdent/the-guide.git'
If you get an error when pushing, the other user might have unchecked the box in the pull request that says “Allow edits from maintainers.” Have them check that box in the pull request view and try again.