Execute the following steps:
- Check if current directory is a valid git repository
- Fetch latest changes from remote
- Check if working directory is clean (no local changes)
- If clean: analyze safety and pull with rebase directly (skip stash operations)
- If dirty: stash changes with
git stash push --include-untracked --keep-index(preserves staging state) - Analyze if rebasing looks safe (check for potential conflicts by comparing commit histories)
- If safe: pull with rebase, then restore stash if needed with
git stash pop - If unsafe: abort and restore stash if needed with
git stash popto return to exact original state - Always provide exactly one sentence summary of the operation result
Safety checks:
- Use
git rev-parse --is-inside-work-treeto verify git repository - Look for divergent commit histories that could cause conflicts
- Check if remote has force-pushed (dangerous for rebase)
- Verify we're on a branch that can be safely rebased
- Use
git status --porcelainto check for local changes efficiently - Only stash/unstash if working directory is dirty
Stash safety rules:
- Use
git stash push --include-untracked --keep-indexto preserve staging state - Always use
git stash popto restore, nevergit stash apply - If stash pop fails due to conflicts, use
git reset --hardandgit stash applythen resolve - Guarantee that abort scenarios restore files to their exact original state (staged files remain staged, unstaged files remain unstaged)
- Never proceed if stashing fails or if restoration would cause data loss
Rules:
- Preserve exact file states (staged/unstaged) through stash operations
- Only proceed with rebase if conflict probability is low
- Always restore original state on abort
- Output exactly one sentence summary at the end
- Zero tolerance for data loss