Last active
June 6, 2024 08:42
-
-
Save nimahkh/bd4aa1632fc0dd767fe2ed1110495767 to your computer and use it in GitHub Desktop.
Git command to add, commit and push together
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
### 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