Skip to content

Instantly share code, notes, and snippets.

@mauvehed
Last active June 11, 2017 13:42
Show Gist options
  • Save mauvehed/b261582b584f9cd22fcd8b144fac4b77 to your computer and use it in GitHub Desktop.
Save mauvehed/b261582b584f9cd22fcd8b144fac4b77 to your computer and use it in GitHub Desktop.

The general idea here is to always use a new branch to create new content you want to submit to the original parent repo, known as upstream. In doing so you'll never work directly from your master branch, you'll instead use new branches for each feature or speaker note.

With this idea in mind, your master branch should always be an up to date version of the upstream repo. The following commands will overwrite your master branch every time you run this. Any changes made there will be destroyed and only the most recent changes from upstream/master will remain. This is intentional, but requires that you never make changes to your local master branch.

1. Add remote upstream (only required the first time):

git remote add upstream git@github.com:REPLACE-YOUR-REPO-NAME/REPLACE-YOUR-REPO-NAME.git

2. Verify it was added (optional):

git remote -v

3. Grab all remote objects:

git fetch --all

4. Sync your local master with the latest from upstream:

git reset --hard upstream/master

5. Push your local master to YOUR origin/github profile (optional):

git push origin master

Lastly I use a shell alias to quickly re-run the commands each time I'm about to create a new branch from master.

6. Add an alias to my shell env

alias gup='gco master && git fetch --all && git reset --hard upstream/master && git push origin master'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment