Git Commit + Push
Follow this workflow to commit and push changes safely with the project's branch rules.
Workflow
- •Confirm repository root and show status.
- •Ensure the working tree is clean after staging.
- •Enforce branch policy:
- •If current branch is
main, create or request afeature/*,chore/*,fix/*,docs/*,refactor/*, ortest/*branch before committing. - •Before creating a new branch from
main, syncmainfirst withgit fetch origin mainthengit pull --ff-only origin main. - •Prefer
chore/<short-desc>for environment/tooling changes.
- •Stage changes with
git add -A. - •If behavior/logic changed, confirm tests were added or updated in the same diff.
- •Create a commit with a clear message.
- •Push with upstream tracking:
git push -u origin <branch>.
Preferred Commands
- •Status:
git status -sb - •Branch:
git branch --show-current - •Sync main then create branch:
git fetch origin main && git pull --ff-only origin main && git checkout -b chore/<short-desc> - •Stage:
git add -A - •Commit:
git commit -m "<message>" - •Push:
git push -u origin <branch>
Bundled Script
Use scripts/commit_push.sh for a consistent flow:
code
./scripts/commit_push.sh ["<message>"] [chore/<short-desc>]
Behavior:
- •If on
main, requires a branch name as the second argument. - •If on
main, it syncs localmainto latestorigin/mainbefore creating the new branch. - •Enforces
feature/*,chore/*,fix/*,docs/*,refactor/*, ortest/*naming. - •Stages, commits, and pushes.
- •If message is omitted, generates one from staged file names.
Notes
- •If there are no changes to commit, stop and report.
- •If behavior changed without corresponding test updates, pause and add tests first.
- •If push fails, surface the error and suggest
git pull --rebaseonly when needed.