Skip to content

Instantly share code, notes, and snippets.

@mmellado
Last active May 11, 2017 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmellado/9047826082718245c562355f34f921d4 to your computer and use it in GitHub Desktop.
Save mmellado/9047826082718245c562355f34f921d4 to your computer and use it in GitHub Desktop.
Sync your forks
function gsync {
# Before using this script, make sure to add upstream to your local repository
# git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
BRANCH="master"
if [ $# -eq 1 ]
then
BRANCH="$1"
fi
# Fetch the latest state of the repository
git fetch --all --tags --prune
# Get the lastest from upstream
echo "Patching with upstream/$BRANCH"
git rebase upstream/$BRANCH
# force push with the latest
echo "Updating origin/$BRANCH with upstream/$BRANCH"
git push --force origin $BRANCH
}
@mmellado
Copy link
Author

mmellado commented Apr 11, 2017

Usage

  • Add script to ~/.bashrc (or your shell profile of preference)
  • Run source ~/.bashrc
  • Go to your repository folder
  • Add the upstream by doing git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
  • Use by typing gsync to sync to upstream/master
  • Alternatively, use gsync [branch] to sync to upstream/branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment