• git

TIL: Switching out git remotes

Say you cloned an interesting git repository and started hacking on it. You now want to open up a PR with your changes, but you obviously don’t have permissions to push to someone else’s repository.

Crap, you’ve got to fork the original repo to your account and create a cross-fork Pull Request. Instead of re-doing all your work again, or messing about with git patches, you can do something simpler:

$ git remote remove origin
$ git remote add origin [email protected]:sdnts/partykit.git

(except, replace the origin URL with your fork)

We’ve just told git to switch out the remote repository’s URL from the original author’s URL to our fork’s URL. This means when you push your changes, you now push to your repository, which you can then create a PR from. Sick!

(Okay this is not really a huge deal, but I felt smart doing it)