Skip to content

Instantly share code, notes, and snippets.

@BelooS
Last active October 14, 2022 19:51
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 BelooS/c099251a8f7e78c0d5839fa2d5989f47 to your computer and use it in GitHub Desktop.
Save BelooS/c099251a8f7e78c0d5839fa2d5989f47 to your computer and use it in GitHub Desktop.
Push changes from directory
#!/bin/bash
set -euxo pipefail
#to use this script first cd to the target directory with changes
GIT_BRANCH="$1"
echo "current dir = $PWD, git branch = $GIT_BRANCH"
git config user.email "$GIT_USER_EMAIL"
git config user.name "$GIT_USER_NAME"
git stash clear
git stash
git pull
git stash pop || echo "Nothing to pop"
git add .
# shellcheck disable=SC2046
if [ $(git diff --staged | wc -m) -eq 0 ]; then
echo "Diff is empty; nothing to commit"
exit 0
fi
echo "perform auto commit"
git commit -m "CI auto update by branch $GIT_BRANCH"
if [ -z "$GIT_BRANCH" ]
then
git push
else
git push --set-upstream origin "$GIT_BRANCH"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment