| name | git-commit |
| description | Safely commit changes with automatic syncing, rebasing, and git hook enforcement |
| version | 1.0.0 |
| author | GitHub Copilot |
| tags | ["git","version-control","commit","rebase","hooks"] |
Git Commit Skill
This skill ensures safe git commits by:
- Fetching the latest changes from remote
- Rebasing from the appropriate branch (same-name remote branch or main)
- Running all git hooks without bypassing them
Prerequisites
- Git repository initialized
- Remote origin configured
- Git hooks configured (if any)
Usage
This skill should be invoked before committing changes to ensure your branch is up-to-date and properly rebased.
Steps
1. Fetch Latest Changes
Fetch all remote branches to ensure we have the latest information:
git fetch origin
2. Determine Current and Target Branch
Get the current branch name:
CURRENT_BRANCH=$(git branch --show-current)
Check if a remote branch with the same name exists:
git ls-remote --heads origin "$CURRENT_BRANCH" | grep -q "$CURRENT_BRANCH"
REMOTE_BRANCH_EXISTS=$?
3. Rebase from Appropriate Branch
If the same-name remote branch exists, rebase from it. Otherwise, rebase from origin/main:
if [ $REMOTE_BRANCH_EXISTS -eq 0 ]; then
echo "Rebasing from origin/$CURRENT_BRANCH"
git rebase "origin/$CURRENT_BRANCH"
else
echo "Rebasing from origin/main"
git rebase origin/main
fi
4. Commit with Hooks Enabled
Stage your changes and commit. Git hooks will run automatically:
git add .
git commit
NEVER use --no-verify or -n flags, as this bypasses git hooks.
Error Handling
-
Rebase Conflicts: If conflicts occur during rebase, resolve them manually:
git add <resolved-files>
git rebase --continue
-
Failed Hooks: If pre-commit or commit-msg hooks fail, fix the issues they report and try again. Do not bypass
hooks.
Example Workflow
git fetch origin
CURRENT_BRANCH=$(git branch --show-current)
if git ls-remote --heads origin "$CURRENT_BRANCH" | grep -q "$CURRENT_BRANCH"; then
git rebase "origin/$CURRENT_BRANCH"
else
git rebase origin/main
fi
git add .
git commit -m "Your commit message"
Notes
- Always resolve rebase conflicts before proceeding
- Git hooks are mandatory and must pass
- If you need to amend a commit, use
git commit --amend (hooks still run)
- Push with
git push origin $CURRENT_BRANCH after successful commit
Safety Guarantees
✅ Always fetches latest remote changes
✅ Rebases from appropriate branch
✅ Never bypasses git hooks
✅ Prevents diverged branch issues
✅ Enforces pre-commit validations