gacm
(Git Add Commit Merge) is a Zsh function that simplifies the process of adding, committing, and optionally pushing Git changes. It combines git add .
, git commit -m
, and (optionally) git push
into a single command, with an additional option for force push.
Add the following function to your ~/.zshrc
file:
gacm() {
local force_push=false
local push=false
local commit_message=""
while [[ $# -gt 0 ]]; do
case "$1" in
-p|--push)
push=true
shift
;;
-f|--force)
force_push=true
shift
;;
*)
commit_message="$1"
shift
;;
esac
done
if [[ -z "$commit_message" ]]; then
echo "Error: Commit message is required."
return 1
fi
git add . && git commit -m "$commit_message"
if $push; then
if $force_push; then
git push --force
else
git push
fi
fi
}
After adding the function, either restart your terminal or run source ~/.zshrc
to apply the changes.
To add all changes and create a commit:
gacm "Your commit message"
To add all changes, create a commit, and push to the remote repository:
gacm -p "Your commit message"
To add all changes, create a commit, and force push to the remote repository:
gacm -p -f "Your commit message"
-p
or--push
: Push changes to the remote repository after committing-f
or--force
: Use force push when pushing changes (must be used with -p)
- If you forget to provide a commit message, the function will display an error message and exit without performing any Git operations.
-
Add and commit changes:
gacm "Add new feature: user authentication"
-
Add, commit, and push changes:
gacm -p "Fix bug in login form"
-
Add, commit, and force push changes:
gacm -p -f "Update project structure"
-
Incorrect usage (will result in an error):
gacm gacm -p gacm -f "Force push without -p option"
- This function uses
git add .
which adds all changes in the current directory and its subdirectories. Be cautious if you have files that you don't want to commit. - The push operation (when using
-p
) pushes to the current branch's upstream. Make sure you have set up the upstream branch correctly. - Force push (
-f
option) should be used with caution as it can overwrite remote changes. - The order of options doesn't matter, but the commit message should always be the last argument.