Pushing Git Changes
Bashgit status --short && git branch --show-current && git remote -v git diff # review unstaged changes git add path/to/file1 path/to/file2 git commit -m "feat(scope): short description" git push # or: git push -u <remote> <branch> if no upstream
Never use git add ., --force, reset --hard, or rebase --skip without reviewing the changes or getting explicit user approval.
Progress:
- [ ] Step 1: Inspect repository state
- [ ] Step 2: Review changes for problems
- [ ] Step 3: Run project checks
- [ ] Step 4: Stage specific files and commit
- [ ] Step 5: Push (set upstream if needed)
- [ ] Step 6: Handle rejection or auth failure
- [ ] Step 7: Confirm result and report
Step 1: Inspect Repository State
Bashgit status git branch --show-current git branch -vv # shows upstream tracking git remote -v git log -5 --oneline
Identify the current branch, configured remote(s), upstream, staged vs. unstaged files, and recent history. Never assume the branch is main/master or the remote is origin.
Step 2: Review Changes
Bashgit status --short git diff # unstaged git diff --cached # staged
Look for:
- Secrets: API keys, passwords, tokens, connection strings,
.envfiles - Debug code (
console.log,Debugger,printstatements, commented-out blocks) - Build artifacts,
node_modules,bin/,obj/,.DS_Store, logs - Unrelated changes that belong in a separate commit
- Environment-specific configuration
If secrets are found: stop, do not commit, tell the user. If a secret was already committed, warn that rotating it is required (removing it from history is not sufficient).
Step 3: Run Project Checks
Detect the project type and use existing scripts. Do not add or upgrade dependencies as part of a push.
| Project | Commands |
|---|---|
| .NET | dotnet restore && dotnet build && dotnet test |
| Node/React/TS | npm install && npm run build && npm run lint && npm test |
| Python | pytest / ruff check . / project-defined scripts |
If a check fails, report the errors and ask whether to fix or proceed. Never claim checks passed if they weren't run. If no checks exist, say so.
Step 4: Stage and Commit
Stage specific files:
Bashgit add src/Inventory/ReceiptValidator.cs tests/ReceiptValidatorTests.cs git commit -m "feat(inventory): add receipt validation"
Use git add . or git add -A only after reviewing the full diff and confirming the user wants everything included.
Commit message format (Conventional Commits):
<type>(<scope>): <imperative description>
| Type | Use for |
|---|---|
feat | New functionality |
fix | Bug fixes |
refactor | Restructuring without behavior change |
docs | Documentation |
test | Tests |
chore | Maintenance, dependencies |
style | Formatting only |
perf | Performance |
Keep the subject under ~72 characters, imperative mood ("add", not "added"). Add a body (git commit with a second -m) when the why isn't obvious. Split unrelated changes into separate commits.
If the repository's history uses a different convention, follow the repository's convention.
Step 5: Push
Bashgit branch -vv # check for upstream
- Upstream exists:
git push - No upstream:
git push -u <remote> <branch-name>
Do not push directly to protected or shared branches (main, master, release/*) without user authorization. If the user is on main and the repository uses pull requests, suggest creating a branch.
Step 6: Handle Failures
Rejected: non-fast-forward / "fetch first"
Bashgit fetch <remote> git log --oneline --graph --decorate --all -15 git status
Explain the divergence to the user (how many commits ahead/behind). Then integrate remote changes:
Bashgit pull --rebase <remote> <branch>
Use merge instead (git pull --no-rebase) if the user prefers it, the branch is shared, or the repo convention is merge commits.
If conflicts occur:
git statusto list conflicted files- Open each file, read both sides, and preserve intent from both where possible
- Remove all conflict markers (
<<<<<<<,=======,>>>>>>>) - Re-run project checks
git add <resolved-files>thengit rebase --continue(orgit commitfor merges)
If the right resolution is unclear, stop and ask the user. Abort safely with git rebase --abort or git merge --abort if things go wrong.
Authentication failure
Bashgit remote -v git config --get credential.helper
Diagnose which applies: expired/missing credentials, personal access token required (HTTPS), SSH key not loaded/registered (ssh -T git@github.com), or insufficient repository permissions. Give the user the fix steps. Never ask for or print passwords or tokens.
Other common errors
| Error | Cause / Action |
|---|---|
src refspec ... does not match any | No commits yet, or wrong branch name. Check git branch and git log. |
remote: Permission denied | Wrong account or no write access. Check remote URL and permissions. |
protected branch hook declined | Push via a feature branch and pull request. |
file exceeds 100 MB | Remove the file from the commit, add to .gitignore, consider Git LFS. |
no upstream branch | Use git push -u <remote> <branch>. |
Step 7: Confirm and Report
Bashgit status git log -1 --stat git branch -vv
Report: branch pushed, remote, commit hash and message, files changed, checks run (and results), and the pull request link if the remote returned one.
Create a new branch before committing when the user asks, or when the current branch is protected:
Bashgit switch -c feature/inventory-receipt-validation
Naming: feature/<description>, fix/<description>, refactor/<description>, docs/<description>, lowercase-kebab-case. Uncommitted changes carry over to the new branch automatically.
Verify the base before branching: git fetch <remote> and confirm the starting point is the intended branch.
Example 1: Standard push
Input: "Commit and push my changes"
Actions: inspect state, find 3 modified files and no secrets, run dotnet build && dotnet test (pass), stage the 3 files, commit fix(category): resolve category loading issue, git push.
Output: "Pushed fix/category-loading to origin. Commit a1b2c3d: 3 files changed. Build and 42 tests passed."
Example 2: No upstream
Input: "Push this branch"
Actions: git branch -vv shows no tracking branch, so git push -u origin feature/export-report.
Output: "Pushed and set upstream to origin/feature/export-report."
Example 3: Rejected push
Input: "Push failed with non-fast-forward"
Actions: git fetch origin, find 2 remote commits not in local history, git pull --rebase origin feature/export-report, resolve a conflict in ReportService.cs preserving both changes, git add, git rebase --continue, re-run tests, git push.
Output: "Rebased onto 2 remote commits, resolved 1 conflict in ReportService.cs (kept both the new filter and the remote null-check). Tests pass. Pushed."
Example 4: Secret detected
Input: "Push everything"
Actions: git diff reveals appsettings.Production.json containing a connection string password.
Output: "Stopped before committing: appsettings.Production.json contains a database password. Recommend adding it to .gitignore and using environment variables or user-secrets. I've staged the other 4 files. Want me to commit those?"
- Always inspect before acting; state what you found.
- Prefer small, focused commits with clear messages.
- Fetch before pushing to shared branches to avoid surprises.
- Prefer
--force-with-leaseover--forcein the rare case a force-push is approved, and only on your own feature branch. - Respect
.gitignore; if a needed pattern is missing, propose adding it. - Preserve the user's uncommitted work: if switching branches or pulling requires a clean tree, ask before using
git stash, and always tell the user what was stashed. - Follow the repository's existing conventions (commit style, branching model, PR process).
- After pushing, mention PR creation if the workflow expects it.
- Blind
git add .: sweeps in secrets, artifacts, and unrelated changes. - Force-pushing to fix a rejection: destroys others' commits. Integrate with rebase or merge instead.
git reset --hardorgit checkout .to "clean up": permanently discards uncommitted work.- Assuming
originandmain: always readgit remote -vand the current branch. - Claiming checks passed without running them.
- Pushing to a protected branch directly.
- Resolving conflicts by taking one side wholesale: loses someone's work; read both sides.
- Committing secrets, then deleting them in a later commit: they remain in history; rotate the credential.
- Vague messages like "update", "fix stuff", "wip".
- Mixing unrelated changes in one commit.
- Requesting or echoing credentials: never ask for passwords or tokens.