Skip to content

Instantly share code, notes, and snippets.

@techiev2
Last active April 30, 2017 21:07
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 techiev2/698b01c5bb0bc4c617a255ee07bbc6ef to your computer and use it in GitHub Desktop.
Save techiev2/698b01c5bb0bc4c617a255ee07bbc6ef to your computer and use it in GitHub Desktop.
Helper script to fetch the latest changed remote and merge to master.
#!/bin/bash
function getRemotes {
remotes=`git branch -r | grep -v HEAD`
local branches=""
for branch in $remotes; do
echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch;
done | sort -r | head -n 1 | awk '{print $7}'
echo $branches
}
echo "Updating remotes"
out=`git remote update`
branch=$(getRemotes)
if [[ $branch == "origin"* ]]; then
echo "No remote changes. Skipping merge and deploy"
exit
fi
echo "Merging from $branch"
out=`git checkout master`
out=`git merge $branch`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment