I often clone a repo on GitHub or GitLab make some changes to it locally and then think I'd like to contribute my changes back to the repo. At that point I always wish I could remember the steps to switch to a fork, so for the benefit of my future self this time I wrote down the steps.

Step 1 - Clone a repo

Most recently I thought I'd have a look at how to contribute to the new winget package manager.

git clone https://github.com/microsoft/winget-pkgs

Step 2 - Make some changes

I updated the version of QuickLook and was ready to push and create a PR when ...

Step 3 - Realise I should have forked first

At this point I remember I have no permissions on this repo, and I should have started from a fork 🤦‍♂️

Step 4 - Fork

So off to GitHub and hit the Fork button which gives me a forked repo at https://github.com/adam7/winget-pkgs

Step 5 - Rename my origin repo to upstream

I'm going to want my fork to be origin so I can push there so let's rename the current origin.

git remote rename origin upstream

Step 6 - Make my fork the origin

Now I can just point origin at my newly forked repo via SSH:

git remote add origin [email protected]:adam7/winget-pkgs
remote add using ssh

or via HTTPS:

git remote add origin https://github.com/adam7/winget-pkgs
remote add using https

Step 7 - Fetch from my new origin

git fetch origin

Step 8 - Set origin main (or master)

Set the upstream of my main branch to point to my fork.  

git branch --set-upstream-to origin/main main

Or if it's an older repo with master instead of main as the default branch.

git branch --set-upstream-to origin/master master

Step 9 - Push to my fork

And now I can push to my forked repo and create a PR.

git push

Step 10 (Optional)

Write this blog post