Commit and push changes to GitHub.
- Run
git statusto see changes - Run
git diffto understand what changed - Check current branch: Run
git branch --show-current. If onmainormaster, STOP and warn the user: "You are on the[branch]branch. Pushing directly to this branch is discouraged. Create a feature branch instead?" Only proceed if the user explicitly confirms they want to push to main/master. - Stage each file by name (e.g.,
git add src/foo.ts src/bar.ts). NEVER usegit add .orgit add -A. Exclude .env, credentials, and large binaries. - Create a commit with a concise message focused on "why" not "what"
- Push to the remote branch
- Verify the push succeeded
Include this line in all commits:
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Troubleshooting
Error: Merge conflict on push
Cause: Remote branch has commits not present locally.
Fix: Run git pull --rebase to rebase local changes on top of remote, resolve any conflicts, then push again.
Error: Authentication failure
Cause: GitHub credentials are expired, missing, or the token lacks push scope.
Fix: Run gh auth status to check auth state. Re-authenticate with gh auth login if needed.
Error: Push rejected to protected branch
Cause: Branch protection rules prevent direct pushes (usually main or master).
Fix: Create a feature branch, push there, and open a PR instead. Do not force-push to protected branches.
Error: No remote configured
Cause: The repo was initialized locally without adding a remote.
Fix: Add a remote with git remote add origin <url> or create a new GitHub repo with gh repo create.