Git Workflow
Core Rules
- Always sync remotes first:
git fetch --all --prune
- Always detect default branch dynamically (fallback
main, then master):default_branch="$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')"
[ -z "$default_branch" ] && default_branch="$(git branch -r --list 'origin/main' | head -n1 | sed 's@^ *origin/@@')"
[ -z "$default_branch" ] && default_branch=master
- Ask for confirmation before destructive operations:
git push --force-with-lease
git reset --hard
- deleting branches/tags
- Never use plain
--force; use --force-with-lease.
- Prefer
origin/<default-branch> as rebase target.
Branch and Commit Conventions
- Branch prefixes:
feature/<name>
fix/<name>
hotfix/<name>
release/<name>
chore/<name>
- Commit prefixes:
feat:, fix:, perf:, refactor:, docs:, test:, chore:, release:
Bundled Helpers
Use these scripts from this skill directory:
scripts/detect-active-branches.sh [--base <branch>] [--window <n>]
scripts/generate-mr-url.sh [source-branch] [target-branch]
generate-mr-url.sh supports generic GitLab remotes (not only git.tec-do.com).
Workflow A: Create Branch
- Ensure repo is up to date:
git fetch --all --prune
- Pick base branch:
- default:
origin/<default-branch>
- use user-provided base if specified
- Normalize branch name:
- If no prefix, infer one from intent (
feature, fix, chore, release, hotfix)
- Convert spaces/underscores to
-
- Create and checkout:
git checkout -b <prefix>/<slug> origin/<base-branch>
- If user asks to publish branch, push:
git push -u origin <branch>
- Show MR URL:
bash scripts/generate-mr-url.sh <branch> <default-branch>
Workflow B: Commit, Push, and MR
1. Branch safety decision
- Detect current branch:
current_branch="$(git branch --show-current)"
- If current branch is protected/integration (
main, master, develop, dev, staging) or user requested new branch:
- create a new branch from
origin/<default-branch> and continue there.
- If current branch is feature/fix style, verify it is not stale:
git cherry "origin/$default_branch" HEAD
- If all commits are already upstream (only
- lines), treat as stale and create a fresh branch.
2. Rebase onto latest default branch
- Stash if worktree is dirty:
git stash push -u -m "git-workflow-auto-stash"
- Rebase:
git rebase "origin/$default_branch"
- If conflicts occur, ask user to resolve and continue:
git rebase --continue
- Restore stash if created:
git stash pop
3. Stage and commit
- Review status:
git status --short
- If user did not ask for partial staging, stage all:
git add -A
- Propose conventional commit title based on diff intent.
- Ask for confirmation/edits on commit message.
- Commit:
git commit -m "<type>: <summary>"
4. Push
- If rebase happened, default to:
git push --force-with-lease origin <current-branch>
Ask for confirmation first.
- Otherwise:
git push -u origin <current-branch>
- Always print MR URL:
bash scripts/generate-mr-url.sh <current-branch> <default-branch>
5. Create MR when requested
If user explicitly requested MR creation:
- Prefer
glab mr create when authenticated.
- Build title/body from commits:
git log "origin/$default_branch"..HEAD --pretty=format:'- %s' --reverse
- Create MR:
glab mr create \
--target-branch "$default_branch" \
--source-branch "$(git branch --show-current)" \
--title "<title>" \
--description "<description>"
- If
glab is unavailable, return URL from generate-mr-url.sh.
Workflow C: Sync Active Feature/Fix Branches
- Save current branch:
origin_branch="$(git branch --show-current)"
- Detect candidates:
bash scripts/detect-active-branches.sh --base "$default_branch"
- Show candidate list and ask user which branches to sync.
- For each selected branch:
git checkout <branch>
git rebase "origin/$default_branch"
- Resolve conflicts with user if needed
- confirm then
git push --force-with-lease origin <branch>
- print MR URL via helper script
- Return to original branch.
Workflow D: Consolidate Integration Branch
Use for requests like "rebuild dev from active features".
- Ask for target integration branch (default
dev).
- Detect active branches using helper script.
- Ask user to confirm branch list and base feature branch.
- Rebase each feature branch on
origin/<default-branch> first.
- Checkout target branch and hard reset to base feature branch:
git checkout <target-branch>
git reset --hard <base-feature-branch>
Ask confirmation before reset.
- Merge remaining feature branches one by one:
git merge --no-ff <feature-branch>
- Ask before push, then push and provide MR URL.
Autonomy Principle
Make reasonable defaults automatically (prefix selection, staging, commit type, target branch).
Ask only when:
- action is destructive
- user intent is ambiguous
- required information cannot be inferred
1---2name: git-workflow3description: Manage day-to-day Git workflow with safe branch creation, conventional commits, rebasing, pushing, MR creation, active-branch sync, and integration-branch consolidation. Use when the user asks to create branches, commit, push, sync feature/fix branches, rebuild dev branches, or open merge requests.4---56# Git Workflow78## Core Rules9101. Always sync remotes first:11 ```bash12 git fetch --all --prune13 ```142. Always detect default branch dynamically (fallback `main`, then `master`):15 ```bash16 default_branch="$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')"17 [ -z "$default_branch" ] && default_branch="$(git branch -r --list 'origin/main' | head -n1 | sed 's@^ *origin/@@')"18 [ -z "$default_branch" ] && default_branch=master19 ```203. Ask for confirmation before destructive operations:21 - `git push --force-with-lease`22 - `git reset --hard`23 - deleting branches/tags244. Never use plain `--force`; use `--force-with-lease`.255. Prefer `origin/<default-branch>` as rebase target.2627## Branch and Commit Conventions2829- Branch prefixes:30 - `feature/<name>`31 - `fix/<name>`32 - `hotfix/<name>`33 - `release/<name>`34 - `chore/<name>`35- Commit prefixes:36 - `feat:`, `fix:`, `perf:`, `refactor:`, `docs:`, `test:`, `chore:`, `release:`3738## Bundled Helpers3940Use these scripts from this skill directory:4142- `scripts/detect-active-branches.sh [--base <branch>] [--window <n>]`43- `scripts/generate-mr-url.sh [source-branch] [target-branch]`4445`generate-mr-url.sh` supports generic GitLab remotes (not only `git.tec-do.com`).4647## Workflow A: Create Branch48491. Ensure repo is up to date:50 ```bash51 git fetch --all --prune52 ```532. Pick base branch:54 - default: `origin/<default-branch>`55 - use user-provided base if specified563. Normalize branch name:57 - If no prefix, infer one from intent (`feature`, `fix`, `chore`, `release`, `hotfix`)58 - Convert spaces/underscores to `-`594. Create and checkout:60 ```bash61 git checkout -b <prefix>/<slug> origin/<base-branch>62 ```635. If user asks to publish branch, push:64 ```bash65 git push -u origin <branch>66 ```676. Show MR URL:68 ```bash69 bash scripts/generate-mr-url.sh <branch> <default-branch>70 ```7172## Workflow B: Commit, Push, and MR7374### 1. Branch safety decision75761. Detect current branch:77 ```bash78 current_branch="$(git branch --show-current)"79 ```802. If current branch is protected/integration (`main`, `master`, `develop`, `dev`, `staging`) or user requested new branch:81 - create a new branch from `origin/<default-branch>` and continue there.823. If current branch is feature/fix style, verify it is not stale:83 ```bash84 git cherry "origin/$default_branch" HEAD85 ```86 - If all commits are already upstream (only `-` lines), treat as stale and create a fresh branch.8788### 2. Rebase onto latest default branch89901. Stash if worktree is dirty:91 ```bash92 git stash push -u -m "git-workflow-auto-stash"93 ```942. Rebase:95 ```bash96 git rebase "origin/$default_branch"97 ```983. If conflicts occur, ask user to resolve and continue:99 ```bash100 git rebase --continue101 ```1024. Restore stash if created:103 ```bash104 git stash pop105 ```106107### 3. Stage and commit1081091. Review status:110 ```bash111 git status --short112 ```1132. If user did not ask for partial staging, stage all:114 ```bash115 git add -A116 ```1173. Propose conventional commit title based on diff intent.1184. Ask for confirmation/edits on commit message.1195. Commit:120 ```bash121 git commit -m "<type>: <summary>"122 ```123124### 4. Push1251261. If rebase happened, default to:127 ```bash128 git push --force-with-lease origin <current-branch>129 ```130 Ask for confirmation first.1312. Otherwise:132 ```bash133 git push -u origin <current-branch>134 ```1353. Always print MR URL:136 ```bash137 bash scripts/generate-mr-url.sh <current-branch> <default-branch>138 ```139140### 5. Create MR when requested141142If user explicitly requested MR creation:1431441. Prefer `glab mr create` when authenticated.1452. Build title/body from commits:146 ```bash147 git log "origin/$default_branch"..HEAD --pretty=format:'- %s' --reverse148 ```1493. Create MR:150 ```bash151 glab mr create \152 --target-branch "$default_branch" \153 --source-branch "$(git branch --show-current)" \154 --title "<title>" \155 --description "<description>"156 ```1574. If `glab` is unavailable, return URL from `generate-mr-url.sh`.158159## Workflow C: Sync Active Feature/Fix Branches1601611. Save current branch:162 ```bash163 origin_branch="$(git branch --show-current)"164 ```1652. Detect candidates:166 ```bash167 bash scripts/detect-active-branches.sh --base "$default_branch"168 ```1693. Show candidate list and ask user which branches to sync.1704. For each selected branch:171 - `git checkout <branch>`172 - `git rebase "origin/$default_branch"`173 - Resolve conflicts with user if needed174 - confirm then `git push --force-with-lease origin <branch>`175 - print MR URL via helper script1765. Return to original branch.177178## Workflow D: Consolidate Integration Branch179180Use for requests like "rebuild dev from active features".1811821. Ask for target integration branch (default `dev`).1832. Detect active branches using helper script.1843. Ask user to confirm branch list and base feature branch.1854. Rebase each feature branch on `origin/<default-branch>` first.1865. Checkout target branch and hard reset to base feature branch:187 ```bash188 git checkout <target-branch>189 git reset --hard <base-feature-branch>190 ```191 Ask confirmation before reset.1926. Merge remaining feature branches one by one:193 ```bash194 git merge --no-ff <feature-branch>195 ```1967. Ask before push, then push and provide MR URL.197198## Autonomy Principle199200Make reasonable defaults automatically (prefix selection, staging, commit type, target branch).201Ask only when:202203- action is destructive204- user intent is ambiguous205- required information cannot be inferred