Skip to content

Instantly share code, notes, and snippets.

@chris-moreton
Last active May 4, 2019 10:51
Show Gist options
  • Save chris-moreton/a5b246ad9f8a65d1fceeb26f1951982d to your computer and use it in GitHub Desktop.
Save chris-moreton/a5b246ad9f8a65d1fceeb26f1951982d to your computer and use it in GitHub Desktop.
Bash function to push all changes to your Git repo from any subdirectory
# A simple function that shows the changed files relative to the root, asks if you want to
# commit all the changes, and then commits and pushes with a given commit messasge.
#
# Usage gpush "This is a commit message"
function gpush() {
RETURN_CMD="cd $PWD"
while [ ! -d ".git" ]
do
if [ $PWD == '/' ]
then
exit
fi
cd ..
done
git status
read -p "Shall we push all this? " SHALL_WE
if [ $SHALL_WE == "y" ]
then
git add -A
git commit -m "$1"
git push
fi
eval $RETURN_CMD
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment