Skip to content

Instantly share code, notes, and snippets.

@nimahkh
Last active June 6, 2024 08:42
Show Gist options
  • Save nimahkh/bd4aa1632fc0dd767fe2ed1110495767 to your computer and use it in GitHub Desktop.
Save nimahkh/bd4aa1632fc0dd767fe2ed1110495767 to your computer and use it in GitHub Desktop.
Git command to add, commit and push together
### Add this code to your .zshrc or .bash_profile
function gacp() {
local files=()
local commit_message=""
while [[ "$#" -gt 0 ]]; do
case $1 in
-m)
shift
commit_message="$1"
break
;;
*)
files+=("$1")
;;
esac
shift
done
if [ ${#files[@]} -eq 0 ] || [ -z "$commit_message" ]; then
echo "Usage: gacp <directory1> <directory2> ... -m <commit message>"
return 1
fi
git add "${files[@]}"
git commit -m "$commit_message"
git push
}
### Usage
# gacp ./ -m "commit message"
# gacp ./directory1 ./directory2 -m "commit message"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment