GitLab MR Manager Skill Instructions
Use the glab CLI to manage GitLab Merge Requests. This skill covers the complete MR lifecycle from creation to merge.
Pre-Flight Check
Verify glab is installed and authenticated:
command -v glab &>/dev/null && echo "glab: installed ($(glab version 2>/dev/null | head -1))" || echo "glab: NOT INSTALLED"; glab auth status 2>&1 | head -3
If glab is not installed, guide the user:
brew install glab
If not authenticated, guide the user through authentication (see Setup section).
Setup
Option 1: Interactive OAuth (Recommended for gitlab.com)
glab auth login
Follow the prompts to authenticate via browser.
Option 2: Personal Access Token
Step 1: Create token at GitLab → Settings → Access Tokens
- •Required scopes:
api,write_repository
Step 2: Add to shell profile:
printf '\nexport GITLAB_TOKEN="your-token-here"\nexport GITLAB_HOST="gitlab.com" # or your self-hosted instance\n' >> ~/.zshrc && source ~/.zshrc
Step 3: Verify:
source ~/.zshrc 2>/dev/null || source ~/.bashrc 2>/dev/null; echo "GITLAB_HOST: ${GITLAB_HOST:-(not set)}"; echo "GITLAB_TOKEN: ${GITLAB_TOKEN:+set}"
Option 3: Authenticate with Token Directly
glab auth login --hostname gitlab.com --token YOUR_TOKEN
For self-hosted GitLab:
glab auth login --hostname gitlab.example.com --token YOUR_TOKEN
Do NOT ask users to paste tokens directly in chat—tokens should stay in their shell profile or be entered via glab auth.
Data Storage
For operations requiring cached data (large MR lists, API responses), store in .claude/skills/glab/:
First-time setup:
mkdir -p .claude/skills/glab && echo '*' > .claude/skills/glab/.gitignore
MR Lifecycle Operations
1. Create MR
From current branch (interactive):
glab mr create
With all details (non-interactive):
glab mr create --fill --title "feat: add new feature" --description "Description here" --target-branch main
Useful flags:
| Flag | Description |
|---|---|
--fill | Use commit info for title/description |
--fill-commit-body | Include all commit messages in description |
-t, --title | MR title |
-d, --description | MR description |
-b, --target-branch | Target branch (default: repo default) |
-s, --source-branch | Source branch (default: current branch) |
-a, --assignee | Assign to username(s) |
-r, --reviewer | Request review from username(s) |
-l, --label | Add labels |
--draft / --wip | Create as draft MR |
--squash-before-merge | Enable squash on merge |
-y, --yes | Skip confirmation prompts |
-w, --web | Open in browser after creation |
Examples:
# Quick MR with auto-filled info glab mr create --fill --yes # Draft MR with reviewers glab mr create --fill --draft --reviewer "username1,username2" # MR with labels and assignee glab mr create --fill --label "bug,priority::high" --assignee "@me" # Open in browser to add more details glab mr create --fill --web
Output: Report MR number and URL: Created !123: https://gitlab.com/group/project/-/merge_requests/123
2. List MRs
Your MRs:
glab mr list --author="@me"
MRs assigned to you:
glab mr list --assignee="@me"
MRs awaiting your review:
glab mr list --reviewer="@me"
Filter by state:
glab mr list --state=opened # opened, closed, merged, all
Filter by labels:
glab mr list --label="bug,priority::high"
Search MRs:
glab mr list --search="authentication"
Output format: Present as table with MR number, title, author, and state.
3. View MR Details
View specific MR:
glab mr view 123
View in browser:
glab mr view 123 --web
View current branch's MR:
glab mr view
Output format:
!123: MR Title Here State: open | Author: username | Created: 2024-01-15 Target: main ← feature-branch Labels: bug, priority::high Assignees: user1, user2 Reviewers: reviewer1 Description: [description text] URL: https://gitlab.com/group/project/-/merge_requests/123
4. Checkout MR Locally
Checkout MR branch:
glab mr checkout 123
Shorthand:
glab co 123
Checkout with specific branch name:
glab mr checkout 123 --branch my-local-branch
This creates a local branch tracking the MR's source branch for review/testing.
5. View MR Diff
View changes:
glab mr diff 123
View in browser:
glab mr diff 123 --web
6. Add Comments/Notes
Add comment:
glab mr note 123 --message "Your comment here"
Multi-line comment (use quotes):
glab mr note 123 --message "Line 1 Line 2 Line 3"
For complex comments, use heredoc:
glab mr note 123 --message "$(cat <<'EOF' ## Review Notes - Point 1 - Point 2 LGTM! EOF )"
7. Approve MR
Approve:
glab mr approve 123
Approve current branch's MR:
glab mr approve
Revoke approval:
glab mr revoke 123
8. Update MR
Update title:
glab mr update 123 --title "New title"
Update description:
glab mr update 123 --description "New description"
Add/change labels:
glab mr update 123 --label "label1,label2"
Remove labels:
glab mr update 123 --unlabel "old-label"
Change assignees:
glab mr update 123 --assignee "username1,username2"
Unassign:
glab mr update 123 --unassign "username"
Add reviewers:
glab mr update 123 --reviewer "reviewer1"
Change target branch:
glab mr update 123 --target-branch develop
Mark as ready (remove draft):
glab mr update 123 --ready
Mark as draft:
glab mr update 123 --draft
Lock discussion:
glab mr update 123 --lock-discussion
9. Rebase MR
Rebase onto target branch:
glab mr rebase 123
This triggers a server-side rebase. Useful when target branch has new commits.
10. Merge MR
Simple merge:
glab mr merge 123
Merge with squash:
glab mr merge 123 --squash
Merge with custom squash message:
glab mr merge 123 --squash --squash-message "feat: implement feature X"
Merge with rebase:
glab mr merge 123 --rebase
Merge when pipeline succeeds:
glab mr merge 123 --when-pipeline-succeeds
Delete source branch after merge:
glab mr merge 123 --remove-source-branch
Combined (common pattern):
glab mr merge 123 --squash --remove-source-branch --when-pipeline-succeeds
11. Close/Reopen MR
Close without merging:
glab mr close 123
Reopen closed MR:
glab mr reopen 123
12. Delete MR
Delete MR (cannot be undone):
glab mr delete 123
13. View Related Issues
List issues that will be closed:
glab mr issues 123
14. Subscribe/Unsubscribe
Subscribe to notifications:
glab mr subscribe 123
Unsubscribe:
glab mr unsubscribe 123
15. Create Todo Item
Add MR to your GitLab todo list:
glab mr todo 123
Advanced: Direct API Access
For operations not covered by glab commands, use the API directly:
Get MR details as JSON:
glab api projects/:id/merge_requests/123 | jq '.'
IMPORTANT: Two Types of MR Comments
GitLab has two types of comments:
- •Inline/Diff comments - attached to specific code lines (returned by
/discussions) - •General notes - not attached to code (returned by
/notes)
Get ALL MR comments (inline + general) - USE THIS FIRST:
glab api "projects/:id/merge_requests/123/notes" | jq '[.[] | select(.system == false) | {body: .body, author: .author.username, created: .created_at}]'
Get inline comments only (with file/line info):
glab api "projects/:id/merge_requests/123/discussions" | jq '[.[] | select(.notes[0].type == "DiffNote") | {file: .notes[0].position.new_path, line: .notes[0].position.new_line, body: .notes[0].body, resolved: .notes[0].resolved}]'
Best practice: When reviewing MR feedback, always fetch from /notes endpoint first to ensure you get ALL comments, then use /discussions if you need file/line locations for inline comments.
Get MR approvals:
glab api "projects/:id/merge_requests/123/approvals" | jq '{approved: .approved, approvers: [.approved_by[].user.username]}'
Get MR changes (diff as JSON):
glab api "projects/:id/merge_requests/123/changes" | jq '.changes[] | {file: .new_path, diff: .diff}'
Reply to a discussion:
glab api "projects/:id/merge_requests/123/discussions/DISCUSSION_ID/notes" -X POST -f "body=Your reply here"
Note: :id is automatically replaced with current project ID when in a git repo.
Working with Other Repositories
Specify repository:
glab mr list -R owner/repo glab mr view 123 -R group/subgroup/project
Full URL also works:
glab mr view 123 -R https://gitlab.com/group/project
Error Handling
| Error | Fix |
|---|---|
| "could not determine base URL" | Run command inside a git repo or use -R flag |
| "401 Unauthorized" | Re-authenticate: glab auth login |
| "403 Forbidden" | User lacks permission for this action |
| "404 Not Found" | Check MR number and repository |
| "Merge request is not open" | MR already merged or closed |
| "Pipeline must succeed" | Wait for CI or use --when-pipeline-succeeds |
| "Merge blocked" | Resolve conflicts or required approvals |
| "glab not found" | Install: brew install glab |
Output Guidelines
- •Be concise: Show key fields, not raw output
- •Include MR URL: Always provide clickable link
- •Show state clearly: open/merged/closed with visual indicator
- •List labels/assignees: When relevant to user's query
- •Pipeline status: Mention if blocking merge
Common Workflows
Quick MR from Feature Branch
git checkout -b feature/my-feature # ... make changes, commit ... git push -u origin feature/my-feature glab mr create --fill --yes
Review and Merge Flow
glab mr list --reviewer="@me" # See MRs to review glab mr checkout 123 # Checkout locally glab mr diff 123 # Review changes glab mr approve 123 # Approve glab mr merge 123 --squash --remove-source-branch # Merge
Draft to Ready Flow
glab mr create --fill --draft # Create as draft # ... iterate on changes ... glab mr update 123 --ready # Mark ready for review
URL Parsing
Extract MR numbers from URLs:
| URL Pattern | MR Number Location |
|---|---|
.../merge_requests/123 | After /merge_requests/ |
.../-/merge_requests/123 | After /-/merge_requests/ |
!123 in text | After ! |