GitLab: Repositories, Branches & Merge Requests
GitLab is a complete DevSecOps platform — combining Git hosting, CI/CD, issue tracking, container registry, and security scanning in one application. Available as SaaS (gitlab.com) or self-managed.
Repository Basics
# Clone via HTTPS or SSH
git clone https://gitlab.com/group/project.git
git clone git@gitlab.com:group/project.git
# GitLab CLI
glab auth login
glab repo clone group/project
# Protected branches — set in Settings → Repository → Protected Branches
# Main/master: typically locked to Maintainers for push, Developers for mergeBranch Strategy
GitLab Flow: feature branches → main → production (add environment branches like staging)
Trunk-based development: short-lived feature branches, merge daily, use feature flags
Protected branches: prevent force-push, require approvals before merge
Default branch: configurable per project (Settings → Repository → Default branch)
Branch naming convention: feature/, fix/, chore/ prefixes recommended
Merge Requests (MRs)
Merge Requests in GitLab are equivalent to GitHub Pull Requests. They are the primary unit of code review.
# Create MR via CLI
glab mr create --title "Add payment flow" --description "Implements Stripe checkout" --target-branch main
# List open MRs
glab mr list
# Check out MR locally
glab mr checkout 42
# Approve and merge
glab mr approve 42
glab mr merge 42MR Settings & Best Practices
Draft MRs: prefix title with "Draft:" to prevent accidental merge while WIP
Assignee: the person responsible for merging; Reviewer: person doing the code review
Approvals: configure required approvals in Settings → Merge Requests → Approval rules
Squash commits: enabled per MR or as project default — keeps main branch history clean
Delete source branch: check "Delete source branch when merge request is accepted"
Rebase on merge: keeps linear history without merge commits
Merge trains: queue MRs that pipeline-test against each other before merging
Code Review Features
Inline comments: click the diff gutter to add a comment on a specific line
Suggestions: click the "Insert suggestion" icon to propose a code change inline — author can apply with one click
Threads: group related comments into a thread; resolve when addressed
Review summary: submit all comments at once instead of notifying per comment
MR dependencies: block an MR from merging until another MR is merged first
Reviewers can filter by file, diff type (inline/side-by-side), or whitespace
Forks & Contributions
Fork: copies the project to your namespace — use for open-source contributions
Fork sync: GitLab can sync forks automatically with the upstream project
Contribution limits: project owners can set who can create branches and MRs
Merge request from fork: create MR targeting upstream repository directly
Keep your own version of these notes — editable, searchable, and organised by your stack.
Start free