Last active
October 14, 2022 19:51
-
-
Save BelooS/c099251a8f7e78c0d5839fa2d5989f47 to your computer and use it in GitHub Desktop.
Push changes from directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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