Updating Forked Repos

Published

I find myself reaching for forked repos more often than direct clones these days, however I always inevitably need to find a way to update my fork based on the original repo. I usually google the answer and find a helpful stack overflow that has the code that I need.

I figured I'd re-share that here both as a personal reference to the snippet of code and if others want to find it as well.

1# First add the original repo as a remote locally
2# here we call that one `upstream`
3git remote add upstream <link-to-original-repo>
4
5# Fetch that upstream repo to ensure we have the latest references
6git fetch upstream
7
8# Checkout the main branch
9git checkout main
10
11# Apply the commits from upstream main to the local main branch
12git rebase upstream/main
13
14# Finally push this back up to the forked remote
15git push origin main
1# First add the original repo as a remote locally
2# here we call that one `upstream`
3git remote add upstream <link-to-original-repo>
4
5# Fetch that upstream repo to ensure we have the latest references
6git fetch upstream
7
8# Checkout the main branch
9git checkout main
10
11# Apply the commits from upstream main to the local main branch
12git rebase upstream/main
13
14# Finally push this back up to the forked remote
15git push origin main