Create a gist now

Instantly share code, notes, and snippets.

@Fweeb /forkicate.sh
Last active Aug 29, 2015

What would you like to do?
Steps to fork a github project
# THIS IS NOT MEANT TO BE A SCRIPT YOU ACTUALLY RUN.
####################################################
# Use these steps to work on a project fork on GitHub and create your own dev branch
# (this assumes that you've already created a fork through GitHub's interface)
cd ~/src # or where ever you keep your source code
git clone https://github.com/YourUser/project.git # Where "YourUser" is your username and "project" is your forked project
cd project
# Track the upstream project you forked from
git remote add --track master upstream git://github.com/ForkedUser/project.git # Where "ForkedUser" is the upstream owner
git fetch upstream
git merge upstream/master # Should already be up to date
# Make your branch and switch to it
git branch mybranch
git checkout mybranch
# Make code changes with whatever tools you can. Let's assume you already have a patch with changes to apply:
patch -p1 < mychanges.patch
# Commit your changes to your branch
git commit -a -m "I made changes. If this were a real comment, I'd be more specific."
# Push your changes back to your fork on GitHub (including the new branch)
git push --set-upstream origin mybranch
# For safety's sake, you may want to make a diff file of your changes (it may help syncing in the future)
git diff master mybranch > mychanges.patch
#################
# Flash forward to the future when changes have been made upstream. You want to sync your branch with upstream
git checkout master
git fetch upstream
git merge upstream/master
# You should probably do a commit after this to commit the merged changes from upstream
git commit -a -m "Merged changes from upstream master"
# Now pull those changes into your branch as per: http://stackoverflow.com/questions/16955980/git-merge-master-into-feature-branch
git checkout mybranch
git rebase master # This will require manually managing conflicts
git rebase --skip
# Now commit your merged changes
git commit -a -m "Merged changes from master"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment