Skip to content

Instantly share code, notes, and snippets.

@JetStarBlues
Last active April 16, 2021 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JetStarBlues/47229585a870614fb4fd993e16e6101b to your computer and use it in GitHub Desktop.
Save JetStarBlues/47229585a870614fb4fd993e16e6101b to your computer and use it in GitHub Desktop.
Keeping a fork up to date

Keeping a fork up to date

Attending the "Getting Started with Open Source" talk at RC today, inspired me to finally figure out how to keep forks up-to-date.

Preamble

  • Always make your changes in a branch
    • this way, you can,
      • keep the main branch of the fork in sync with upstream
      • ?

Steps

  1. Add an upstream url if not already present
    • check current remote urls with git remote -v
    • if upstream entry not present, add with git remote add upstream repoUrl.git
      • for example, git remote add upstream https://github.com/octocat/Spoon-Knife.git
  2. Get the current status? of upstream with git fetch upstream
  3. Switch to main branch of local repository with git switch main or git checkout main
    • in some repositories, the main branch is called master
  4. Merge changes from upstream with git merge upstream/main
    • this brings the main branch of your local repository up to date with the upstream
    • alternatively, git rebase upstream/main can be used. (Not sure which is better).
  5. Push changes to your fork (origin) with git push
    • this brings the main branch of your origin repository up to date with the upstream

Resources used (in addition to talk):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment