GitLab Basics: Repos, Merge Requests & CI Integration
In this tutorial, you'll learn about GitLab Basics: Repos, Merge Requests & CI Integration. We cover key concepts, practical examples, and best practices.
GitLab provides source code management, CI/CD pipelines, and container registry as an integrated DevOps platform available as SaaS or self-hosted.
In this tutorial, you'll learn GitLab fundamentals for managing code repositories, collaborating via merge requests, and integrating CI/CD pipelines. GitLab is a complete DevOps platform — not just Git hosting, but also CI/CD, container registry, and deployment. By the end, you'll create projects, use merge requests, and configure pipelines.
flowchart TD
A[Create GitLab project] --> B[Clone locally]
B --> C[Create feature branch]
C --> D[Push changes]
D --> E[Create merge request]
E --> F[CI pipeline runs]
F --> G{All checks pass?}
G -->|No| H[Fix and push]
H --> F
G -->|Yes| I[Request review]
I --> J{Approved?}
J -->|No| K[Address feedback]
K --> I
J -->|Yes| L[Merge]
Creating a GitLab Project
GitLab calls repositories projects. Create one via UI or CLI:
# Using GitLab CLI (glab)
glab project create my-project --public
# Or use standard Git workflow
mkdir my-project && cd my-project
git init
git remote add origin https://gitlab.com/your-username/my-project.git
git add .
git commit -m "Initial commit"
git push -u origin main
GitLab Merge Requests
Merge requests are GitLab's equivalent of GitHub pull requests:
# Create a feature branch
git checkout -b feat/user-auth
# Make changes and push
echo "auth code" > auth.py
git add auth.py
git commit -m "feat(auth): add user authentication"
git push -u origin feat/user-auth
On GitLab, create a merge request from the branch. MRs include:
- Description with templates
- Linked issues (using
Closes #42) - Related merge requests
- Pipeline status
- Approval tracking
CI/CD Integration
GitLab CI/CD is built in — every project has pipelines. Create .gitlab-ci.yml:
stages:
- test
- build
- deploy
test:
stage: test
image: python:3.11
script:
- pip install -r requirements.txt
- pytest
artifacts:
reports:
junit: report.xml
build:
stage: build
image: docker:latest
services:
- docker:dind
script:
- docker build -t my-app .
only:
- main
Code Review with Merge Requests
GitLab's merge request workflow includes:
| Feature | Purpose |
|---|---|
| Approvals | Require N approvals before merge |
| Merge checks | Pipeline must pass |
| Discussions | Threaded comments on code |
| Suggestion | One-click code change acceptance |
| WIP/Draft MR | Mark as work in progress |
| Merge options | Merge commit, squash, rebase |
GitLab Container Registry
Every project has a built-in container registry:
# Login to GitLab container registry
docker login registry.gitlab.com
# Build and push
docker build -t registry.gitlab.com/your-username/my-project:latest .
docker push registry.gitlab.com/your-username/my-project:latest
# Use in CI
image: registry.gitlab.com/your-username/my-project:latest
GitLab Pages
Deploy static sites from GitLab:
pages:
stage: deploy
script:
- mkdir .public
- cp -r * .public/
- mv .public public
artifacts:
paths:
- public
only:
- main
Comparison: GitLab vs GitHub
| Feature | GitLab | GitHub |
|---|---|---|
| CI/CD | Built-in, .gitlab-ci.yml |
GitHub Actions, .github/workflows/ |
| Container registry | Built-in | GitHub Packages |
| Self-hosting | Yes (CE/EE) | No (GHES available) |
| Issue boards | Built-in | Projects (beta) |
| Wiki | Per project | Optional |
| Merge/Pull requests | Merge Requests | Pull Requests |
| Auto DevOps | Yes | No |
| Security scanning | Built-in (Ultimate) | Dependabot, CodeQL |
Common Errors
| Error | Cause | Fix |
|---|---|---|
You are not allowed to push to this branch |
Branch protected | Create feature branch or get maintainer access |
Pipeline stuck |
No runners available | Check shared/group runners or install a runner |
fatal: repository not found |
Wrong project path | Verify full path (namespace/project) |
MR cannot be merged |
Pipeline failed or missing approvals | Fix pipeline or request approvals |
Container registry disabled |
Admin disabled it | Enable in project Settings > General |
Impeded by merge conflict |
Outdated branch | Rebase on target branch |
404 Not Found in registry |
Wrong image name format | Use full registry path |
Your project has no CI/CD config |
Missing .gitlab-ci.yml |
Create the file in repository root |
Practice Questions
Challenge
Create a GitLab project with a Python application. Configure CI/CD with three stages: lint (flake8), test (pytest with coverage), and build (Docker image). Push the code and verify the pipeline runs. Create a merge request from a feature branch, add a reviewer, and complete the merge.
Real-World Task
Set up a GitLab project with the complete DevOps workflow: (1) Create project with README and license, (2) Configure CI/CD with test, lint, and deploy stages, (3) Set up the container registry and push a Docker image, (4) Configure GitLab Pages for documentation, (5) Set up merge request approvals requiring at least 2 reviewers. This mirrors how DodaTech manages internal projects on self-hosted GitLab for tools like DodaZIP.
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro