gitlab-org/gitlab
Source code management
Git hosting plus the social layer (commits, branches, tags, merge requests, code review, approvals).
Source
app/models/
├── project.rb
├── repository.rb
├── commit.rb, commits.rb
├── merge_request.rb, merge_requests/
├── branch.rb, ref.rb, ref_matcher.rb
├── protected_branch.rb, protected_tag.rb
├── deploy_key.rb, ssh_key.rb
└── ...
app/services/
├── projects/ # ~14 service namespaces
├── branches/ # branch CRUD
├── repositories/ # archive, language detection
├── merge_requests/ # ~6 namespaces; the largest
├── protected_branches/, protected_tags/, protected_refs/
├── git/ # git callbacks (post-receive)
├── files/ # file edits via UI / API
└── commits/, compare_service.rb
app/controllers/projects/
app/controllers/projects/merge_requests/
lib/api/
├── repositories.rb, repository_*.rb
├── branches.rb, tags.rb, commits.rb
├── merge_requests.rb, merge_request_*.rb
└── files.rb
ee/ # extra MR rules, code owners, etc.Frontend lives under app/assets/javascripts/{repository,merge_requests,diffs,notes,...}/.
Repository lifecycle
graph LR
User -->|git push| Shell[GitLab Shell]
User -->|git push HTTPS| WH[Workhorse]
Shell -->|gRPC| Gitaly
WH -->|gRPC| Gitaly
Gitaly -->|post-receive hook| Internal[Internal API]
Internal -->|enqueue| PostReceiveWorker
PostReceiveWorker --> Hooks[Web hooks]
PostReceiveWorker --> Pipelines[CI pipeline create]
PostReceiveWorker --> MRs[MR refresh]
PostReceiveWorker --> Notif[Notifications]The post-receive flow is in app/services/post_receive_service.rb, with downstream concerns dispatched via the EventStore.
Merge requests
The MR domain is the largest in the codebase:
- Models:
app/models/merge_request.rb,merge_requests/,merge_request_diff.rb,merge_request_diff_commit.rb,merge_request_metric.rb, plus EE subscribers. - Services:
app/services/merge_requests/— create, update, refresh, merge, rebase, squash, conflict resolution, mergeability checks, etc. - Controllers and views:
app/controllers/projects/merge_requests/,app/views/projects/merge_requests/. - Frontend:
app/assets/javascripts/merge_requests/,app/assets/javascripts/diffs/,app/assets/javascripts/notes/,batch_comments/. - Mergeability:
lib/gitlab/merge_requests/mergeability/— rule-based checks. - Approval rules: EE under
ee/app/services/approval_rules/and friends. - Code owners: EE under
ee/app/services/code_owners/. - Auto-merge:
app/services/auto_merge/. - Conflict resolution: backed by Gitaly's
ConflictsService.
Code review
- Discussion threads (
Discussion,Note,DraftNote) layered on top of merge requests. - Suggestions (Markdown
```suggestionblocks) applied viaapp/services/suggestions/. - Review apps: rendered by the CI pipeline; surfaced in the MR widget.
- Approvals (EE): rules + minimum approvers per branch.
Diff browsing
app/services/git/, lib/gitlab/diff/, and the frontend at app/assets/javascripts/diffs/ cover the diff browser. Performance-critical:
- Diffs are cached per-MR-version.
- File-level pagination and lazy-loading.
- Whitespace-only diff filtering (configurable).
Branches and protected refs
ProtectedBranch,ProtectedTagdefine push/merge access by user/role/regex.- The cop
Gitlab::PolicyRuleBooleanensures correct condition combinators.
Code Owners
EE-only. ee/app/services/code_owners/ parses CODEOWNERS files in the repo, attaches owners to MRs, and feeds approval rules.
Push rules
EE feature in ee/app/services/projects/push_rules/. Validates commit messages, branch names, file sizes, and other constraints at push time via Gitaly hooks.
Squash, rebase, cherry-pick, revert
All implemented in app/services/merge_requests/{squash_service.rb, rebase_service.rb} and app/services/commits/cherry_pick_service.rb, revert_service.rb. They call Gitaly's OperationService.
API
- REST:
lib/api/merge_requests.rb,lib/api/branches.rb,lib/api/commits.rb,lib/api/repositories.rb. - GraphQL:
app/graphql/types/merge_request_type.rb,app/graphql/mutations/merge_requests/,app/graphql/resolvers/merge_requests/.
Related
- Gitaly client — every Git read/write goes through this.
- Workhorse — git over HTTP and archive download acceleration.
- CI/CD — pipelines triggered on push.
- Geo — repository replication.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.