GitHub branch management for
upstream remote projects using
My GitHub branch-management process, first attempted with OpenShot/openshot-qt but now the one I use on all projects.
After creating my fork in the web interface
$ git clone <my fork SSH identifier>; cd $PROJECT $ git remote add upstream <upstream HTTPS URL> $ git fetch upstream From https://github.com/... $ # $DEFAULT is the project default branch name, usually 'master' but sometimes 'develop' or whatever $ git branch -u upstream/$DEFAULT $DEFAULT Branch '$DEFAULT' set up to track remote branch '$DEFAULT' from 'upstream'.
So now, the default branch tracks the upstream. I never touch that branch in my own fork, in fact I don't even have a local copy of it. It just allow it to fall wildly out of date, since it never updates past the point where I forked the upstream project.
When I want to write code for a PR...
$ git checkout $DEFAULT $ git pull # Sync with upstream/$DEFAULT $ # Create a new topic branch based on local $DEFAULT, which tracks upstream/$DEFAULT $ git checkout -b newtopic $DEFAULT $ git push -u origin newtopic # I do this immediately, before writing any code, to configure it Total 0 (delta 0), reused 0 (delta 0) remote: remote: Create a pull request for 'newtopic' on GitHub by visiting: remote: https://github.com/ferdnyc/$PROJECT/pull/new/newtopic remote: To github.com:ferdnyc/$PROJECT.git * [new branch] newtopic -> newtopic Branch 'newtopic' set up to track remote branch 'newtopic' from 'origin'.
Then after committing any changes, I can just...
$ git push remote: Resolving deltas: ... To github.com:ferdnyc/$PROJECT.git $GITREFA..$GITREFB newtopic -> newtopic
After I finish development on newtopic...
$ git checkout $DEFAULT # Return to upstream/$DEFAULT as my base branch $ git pull # Sync with upstream/$DEFAULT
And if I need to return to newtopic...
$ git checkout newtopic $ git merge develop # If there's already a PR, it's easier/cleaner to do this on the web and pull.