Skip to content

Instantly share code, notes, and snippets.

@fijiwebdesign
Last active August 29, 2015 14:13
Show Gist options
  • Save fijiwebdesign/527aa365ce8fb4ef80d3 to your computer and use it in GitHub Desktop.
Save fijiwebdesign/527aa365ce8fb4ef80d3 to your computer and use it in GitHub Desktop.
Git fork a repo and keep updated with original repo
# **fork repo via github UI**
# clone locally
git clone <repo-location>
# add a remote called "upstream" pointing to original repo location
git remote add upstream <repo-location>
# now you have two remotes, "origin" which is the forked repo and "upstream" which is the original
# create a new branch
git checkout -b <branch-name>
# make some changes
echo "Hello" >> README.md
# commit changes
git commit -am "Add Hello to README.md"
# push chagnes to your branch
git push origin <branch-name>
# **create a pull request in github UI**
# switch to your forked repo's master (checkout your local master branch)
git checkout master
# fetch the changes in original repo to your local copy
# Fetch the branches and their respective commits from the upstream repository. Commits to master will be stored in a local branch, upstream/master.
git fetch upstream
# merge original repo's changes on top of your local copy
git rebase upstream/master
# or if you have changes
git merge upstream/master
# push your local changes to origin/master (your fork's master branch)
git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment