Git Safe Sync Skill
This skill handles the safe synchronization of the local repository with the remote. It features:
- •Automatic Commit Message Generation: intelligently writes commit messages based on changes if none is provided.
- •Smart Sync: Checks if a pull is actually needed before attempting it, avoiding unnecessary operations and potential errors.
Workflow
- •
Check Status:
- •Run
git statusto see if there are any changes. - •If the working tree is clean and
git statussays "nothing to commit", proceed to Step 4 (Sync Check) to ensure we are up to date with remote, or exit if the goal was only to commit.
- •Run
- •
Stage Changes:
- •Run
git add .to stage all modified and untracked files.
- •Run
- •
Generate Commit Message & Commit:
- •Context Check: Did the user explicitly provide a commit message in their request?
- •IF YES:
- •Use that message. Run
git commit -m "USER_MESSAGE".
- •Use that message. Run
- •IF NO:
- •Analyze the staged changes. Run
git diff --cached --statorgit diff --cachedif needed. - •GENERATE a concise, conventional commit message based on the changes.
- •Format:
type(scope): description - •Types:
feat,fix,docs,style,refactor,perf,test,chore. - •Example:
fix(cart): resolve issue with sticky cart cutoff - •Keep the subject line under 50 characters.
- •Format:
- •Run
git commit -m "GENERATED_MESSAGE".
- •Analyze the staged changes. Run
- •
Smart Sync Check:
- •Run
git fetchto get the latest remote status. - •Run
git status -unoto check the relationship with the remote branch. - •Analyze Output:
- •"Your branch is behind...": A pull is needed. Run
git pull --rebase. - •"Your branch and 'origin/main' have diverged...": A pull is needed. Run
git pull --rebase.- •Note: If conflicts occur during rebase, STOP and inform the user.
- •"Your branch is ahead...": No pull needed. Proceed to Push.
- •"Your branch is up to date...": No pull needed.
- •If you just made a commit, you are now "ahead", so Proceed to Push.
- •If you didn't make a commit and are "up to date", the sync is complete. Exit.
- •"Your branch is behind...": A pull is needed. Run
- •Run
- •
Push:
- •Run
git pushto upload changes.
- •Run
- •
Completion:
- •Report the successful sync, the commit message used (if auto-generated), and whether a pull was performed.