/git-push-workflow
Critical Constraints
- NEVER work directly on
main— always create a feature branch first - NEVER force push to
main - NEVER merge to
mainyourself — always use a pull request (GitHub) or merge request (GitLab)
Branch Naming
feature/*— new featuresfix/*— bug fixeschore/*— maintenance tasks (dependencies, config)refactor/*— code refactoringdocs/*— documentation only
Branch Workflow
git checkout main && git pull origin maingit checkout -b <type>/branch-name- Make changes, commit as needed
- When ready, follow the push steps below
Commit message format
<type>: <subject>
- Types:
feat,fix,chore,refactor,docs,test - Keep subjects under 50 characters, imperative mood ("add" not "added")
Steps
Detect remote platform — run
git remote get-url origin:- If
originis not configured, stop and ask the user to set up theoriginremote before continuing. - If URL contains
github.com→ GitHub (usegh prfor PR creation) - If URL contains
gitlab.com(or your self-hosted GitLab instance) → GitLab (useglab mrfor MR creation)
- If
Stage and commit (if there are uncommitted changes):
- Stage relevant files — never stage
.env, credentials, or secrets - If no uncommitted changes, skip to step 3
- Stage relevant files — never stage
Squash all branch commits into one:
- Count commits ahead of
origin/main - If more than one commit:
git reset --soft origin/mainthengit commitwith the final message - If exactly one commit: skip squash
- Count commits ahead of
Rebase on latest main:
git fetch origin maingit rebase origin/main- Resolve any conflicts. Only ping the user if you're unsure how to resolve a specific conflict; otherwise resolve and continue.
Push and create PR/MR:
- GitHub:
git push origin HEAD -f, thengh pr create --base main --title "<commit subject>" --body "<commit body or summary>" - GitLab:
git push origin HEAD -o merge_request.create -o merge_request.target=main -f(creates the MR via push options in one command)
- GitHub:
Set PR/MR title to match the squashed commit message:
- GitHub: title is set during
gh pr create(step 5) — nothing more to do - GitLab:
glab mr update <MR_NUMBER> --title "<commit subject line>"
- GitHub: title is set during
Report the PR/MR URL from the push output (GitLab) or the
gh pr createoutput (GitHub).