Skip to content

Instantly share code, notes, and snippets.

@terabyte
Created March 25, 2022 03:41
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 terabyte/5ce40acf5d281a2550da941b8125d86e to your computer and use it in GitHub Desktop.
Save terabyte/5ce40acf5d281a2550da941b8125d86e to your computer and use it in GitHub Desktop.
Script to fetch any updates and merge it into any currently unincorporated work, then push it.
#!/bin/bash
set -e
GIT_DIR=$HOME/projects/private_notes
# only do it if we have network
if ping -c1 -w5 -n 8.8.8.8 | grep -q '1 received'; then
# first fetch updates
git -C $GIT_DIR fetch -q origin > /dev/null
if [[ "x$(git -C $GIT_DIR status --porcelain)" == "x" ]]; then
git -C $GIT_DIR merge origin/master
fi
git -C $GIT_DIR fetch -q origin > /dev/null
git -C $GIT_DIR merge -q -m"Merging in update" origin/master > /dev/null
git -C $GIT_DIR push -q origin master > /dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment