This error occurs when GitLab push rules reject your commit because the commit message doesn't match the required regex pattern. You need to amend your commit message to include required elements like issue numbers, ticket references, or specific formats.
The error "remote: GitLab: Commit message does not follow the pattern" means your GitLab repository or group has **push rules** configured that enforce a specific commit message format. When you push commits, GitLab validates each commit message against a regular expression pattern, and if any commit doesn't match, the entire push is rejected. Push rules are a GitLab feature that helps teams enforce commit message conventions. Common requirements include: - Referencing issue/ticket numbers (e.g., "JIRA-123", "Fixes #456") - Following conventional commit formats (e.g., "feat:", "fix:", "docs:") - Including specific keywords or project identifiers This is a server-side validation that cannot be bypassed without changing your commit message or having an admin modify the push rules. The error will show you the exact regex pattern that your commit message failed to match.
First, look at the error message to see what pattern is required:
# The error typically looks like:
remote: GitLab: Commit message does not follow the pattern 'JIRA-\d+'
# Or
remote: GitLab: Commit message does not follow the pattern 'workitem \d+'
# Or
remote: GitLab: Commit message does not follow the pattern '^(feat|fix|docs|style|refactor|test|chore):'The pattern in quotes is a regular expression (regex). Common patterns include:
- JIRA-\d+ - Requires JIRA ticket like "JIRA-123"
- workitem \d+ - Requires work item number
- #\d+ - Requires issue number like "#456"
- ^(feat|fix|docs): - Requires conventional commit prefix
Once you know the pattern, you can format your commit message accordingly.
Use git commit --amend to modify your most recent commit message:
# Amend the last commit with a new message
git commit --amend -m "JIRA-123: Add initial project setup"
# Or for conventional commit format
git commit --amend -m "feat: add initial project setup (#123)"
# Or open an editor to modify the message
git commit --amend
# Then force push if you already pushed the old commit
git push --force-with-leaseTips for matching common patterns:
- Include the ticket number at the start: "JIRA-456: Your message"
- Use conventional commits: "fix: resolve login bug"
- Reference issues: "Add feature (closes #789)"
The message just needs to contain the required pattern somewhere—it doesn't always need to be at the beginning.
If multiple commits need message changes, use interactive rebase:
# Rebase the last N commits (e.g., last 3)
git rebase -i HEAD~3
# In the editor, change 'pick' to 'reword' for commits you want to edit:
# reword abc1234 Initial commit
# pick def5678 Add feature
# reword ghi9012 Fix bug
# Save and close. Git will pause at each 'reword' commit
# Edit each message to include the required pattern
# After completing the rebase, force push
git push --force-with-leaseWarning: Interactive rebase rewrites history. Only do this for commits that haven't been shared with others, or coordinate with your team before force pushing.
View the push rules configured for your project:
1. Project-level rules:
- Go to your project in GitLab
- Navigate to Settings → Repository
- Expand Push rules
- View "Require expression in commit messages"
2. Group-level rules:
- Go to your group
- Navigate to Settings → Repository
- Check the Push rules section
3. Instance-level rules (admin only):
- Admin Area → Push Rules
- These serve as templates for new projects
GitLab uses RE2 regex syntax. Test patterns at [regex101.com](https://regex101.com) with the "Golang" flavor selected.
Important: Commit messages in GitLab UI use \r\n for newlines. If you see patterns with \n, they might need (\r\n?|\n) for cross-platform compatibility.
If the push rules are too restrictive or causing legitimate issues:
Ask your team lead or GitLab admin to:
1. Review the regex pattern - The pattern might be incorrectly configured
2. Add exceptions for merge commits - Merge commit messages are auto-generated
3. Exclude certain branches - Some rules shouldn't apply to all branches
4. Update the pattern - Make it more flexible while maintaining standards
For merge commit issues:
# If pattern '^Merge.*$' fails on merge trains,
# the admin can adjust to handle GitLab's auto-generated format
^(Merge|feat|fix|docs|chore|refactor|test|style):?.*For CI/CD tools like semantic-release:
Some tools push git notes or automated commits that may not match patterns. Admins can exclude these by updating rules or adjusting the tool configuration.
Prevent rejected pushes by validating commit messages locally before pushing:
# Create a commit-msg hook
cat > .git/hooks/commit-msg << 'EOF'
#!/bin/bash
# Pattern required by your GitLab (adjust to match your rules)
PATTERN="JIRA-[0-9]+"
MESSAGE=$(cat "$1")
if ! echo "$MESSAGE" | grep -qE "$PATTERN"; then
echo "ERROR: Commit message must contain a JIRA ticket (e.g., JIRA-123)"
echo "Your message: $MESSAGE"
exit 1
fi
EOF
chmod +x .git/hooks/commit-msgFor team-wide hooks, use a shared hooks directory:
# In your project root
mkdir -p .githooks
# Add your commit-msg hook there
# Configure git to use it
git config core.hooksPath .githooks
# Commit the hooks to share with team
git add .githooksThis catches invalid commit messages before they're created, saving you from amending later.
If automated tools like semantic-release, Renovate, or GitLab CI fail:
For semantic-release:
// In your release.config.js, format commits to match push rules
module.exports = {
plugins: [
['@semantic-release/commit-analyzer', {
releaseRules: [
{ type: 'feat', release: 'minor' },
{ type: 'fix', release: 'patch' }
]
}],
['@semantic-release/release-notes-generator'],
['@semantic-release/git', {
// Customize commit message to match your pattern
message: 'chore(release): ${nextRelease.version} [skip ci] JIRA-0'
}]
]
};For Renovate:
{
"commitMessagePrefix": "JIRA-0: ",
"commitMessageTopic": "{{depName}}"
}For git notes issues:
Git notes are sometimes validated against commit message rules. You may need to ask your admin to exclude refs/notes/* from push rules or use a workaround:
# Push notes separately with a different configuration
GIT_NOTES_REF=refs/notes/commits git push origin refs/notes/*### Understanding GitLab Push Rules
Push Rule Hierarchy:
1. Instance-level (Admin Area) - Templates for new projects
2. Group-level - Apply to all projects in the group
3. Project-level - Override group settings for specific projects
When you create a new project, it inherits rules from the group or instance level. After creation, project rules are independent copies—changes to group rules don't automatically propagate.
### Common Regex Patterns
JIRA ticket required:
JIRA-\d+
# Matches: JIRA-123, feat: add login JIRA-456
# Fails: Initial commit, fix bugConventional commits:
^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?!?:
# Matches: feat: add login, fix(auth): resolve bug
# Fails: Add new feature, Fixed the bugIssue reference required:
(closes?|fixes?|resolves?)\s+#\d+
# Matches: closes #123, Fixes #456
# Fails: Add feature, Updated docsReject merge commits (use with caution):
^Merge branch
# Rejects auto-generated merge commit messages### RE2 Regex Syntax Notes
GitLab uses RE2, which has some limitations compared to PCRE:
- No lookahead/lookbehind assertions
- No backreferences
- Limited to 511 characters
Multiline handling:
- RE2 has multiline mode enabled by default
- Disable with (?-m) at the start of the pattern
- For cross-platform newlines, use (\r\n?|\n) instead of \n
### Rejecting Patterns
Besides requiring patterns, you can also reject them:
Reject WIP commits:
^\[?WIP\]?
# Rejects: WIP: working on feature, [WIP] testingReject trailing punctuation:
[[:^punct:]]\b$
# The word boundary prevents false negatives from trailing newlines### Merge Request Integration
Push rules can conflict with merge request workflows:
1. Squash commits: When squashing, ensure the final message matches
2. Merge commits: Auto-generated messages may not match patterns
3. Merge trains: Can fail if merge commit messages don't comply
Best practices:
- Configure merge commit templates in project settings
- Allow merge commit patterns in your regex
- Use semi-linear history to avoid merge commits
### Debugging Push Rule Failures
# View your commit messages before pushing
git log --oneline origin/main..HEAD
# Test a message against a pattern locally
echo "Your commit message" | grep -E "JIRA-\d+"
# See the full commit message
git log -1 --format=%B### GitLab Premium/Ultimate Features
Some push rule features require higher tiers:
- Reject unsigned commits - Require GPG-signed commits
- Reject commits by committer - Verify committer email
- Branch name requirements - Enforce branch naming conventions
These work alongside commit message rules for comprehensive governance.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git