From 0c928af7e835d195d5a8089b1eed521314b25008 Mon Sep 17 00:00:00 2001 From: Ava Gaiety Wroten Date: Sun, 2 Feb 2020 10:11:32 -0600 Subject: [PATCH] Git working with forked repos --- content/posts/working-with-forked-repos.md | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 content/posts/working-with-forked-repos.md diff --git a/content/posts/working-with-forked-repos.md b/content/posts/working-with-forked-repos.md new file mode 100644 index 0000000..9d6814a --- /dev/null +++ b/content/posts/working-with-forked-repos.md @@ -0,0 +1,35 @@ +--- +title: Working With Forked Repos +description: Fetching upstream and things +date: 2019-02-02 +tags: + - Tech +--- + +Though I've been building web apps for many years, my direct experience with contributing to open source projects is surprisingly limited. Thus when I found myself forking and maintaining a fork as I submitted several PR's for a single project over time I was a little lost with what to do. + +So here are some things I've learned thus far. + +## Why Fork, and How do I Fork? + +Github, Gitlab and other source-code repositories allow for you to "fork" code. I previously thought this was to split work into a different direction, but in fact its also to give a developer control over proposed changes they'd like to push back to source. Thus, submitting a PR to an open source repository looks like this: + +1. Click `Fork` on the source-code repository +2. Clone your newly forked repository +3. Make your changes on a new branch +4. Push your branch to your forked repository (A misconception I had was you may not push a branch to many open source repositories directly, this is intentional) +5. Create a PR that merges your branch from your fork to the original non-forked repository + +## Updating the Forked Master Branch + +Over time your forked repository will get out of date. A common scenario is desiring to get the latest master from the source repository. + +```bash +git remote add upstream ORIGINAL_PROJECT_CLONE_URL +git fetch upstream +git checkout master +git rebase upstream/master +``` + +Now you may do all the standard things you wish, such as merging master into your current branch `git merge master` to stay up to date with your proposed changes. +