Skip to content

Instantly share code, notes, and snippets.

@shlomiassaf
Last active May 26, 2016 22:31
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 shlomiassaf/ef4aed47985d293445cdac0cc3ce50cc to your computer and use it in GitHub Desktop.
Save shlomiassaf/ef4aed47985d293445cdac0cc3ce50cc to your computer and use it in GitHub Desktop.
A bash script for automatic sync between a local fork, it's origin and the upstream (on GitHub)
# Flow:
# Find origin
# Find upstream URL
# Go to master
# Rebase upstream to master
# push changes to origin
# Make sure master has not pending changes for commit
# Some credits to an unknown source...
url=$(git config --get remote.origin.url)
# Get the user and repo part from the URL
# Must be something like part=${url#*//*/}
# Sticking to github specific code as of now.
part=${url#*github.com*/}
upstream=$(curl -s https://api.github.com/repos/${part%.git} | sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | grep '"git_url":' | sed 's/:/ /1' | awk -F" " '{ print $2 }' | uniq | tail -1)
git checkout master
git pull upstream master --rebase
git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment