git: updating your fork to match the source/parent/upstream #464
naomi-lgbt
started this conversation in
Tips and Tricks
Replies: 1 comment
-
Thank you @nhcarrigan for this and also for the tips folder 👍 https://github.com/EddieJaoudeCommunity/support/blob/main/tips/git.md |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello~!
You'll likely run in to situations where your forked version of a project "falls behind" the state of the source version. GitHub will allow you to make a pull request to bring the changes from the source into your fork, which does work, but creates a merge commit that will show up every time you create a PR back to the source.
Instead, to keep the commit history clean, you can
rebase
your fork against the source. Here are the steps to do so:git checkout <branchname>
. Most commonly, this will begit checkout main
.git fetch upstream
. IF it throws an error that there is no upstream, you'll need to set it ↓git remote add upstream <url>
, where the URL is the clone URL for the source repository.git reset --hard upstream/<branchname>
, wherebranchname
is the name of the primary branch. So, most likelygit reset --hard upstream/main
.git push -f
.https://github.com/nhcarrigan/code-snippets/blob/main/git-commands/git-update-fork.sh
I also have the commands saved in my notes, if you'd like to reference them as shell commands.
Beta Was this translation helpful? Give feedback.
All reactions