iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

GitLab

GitLab is the second most popular Git host and the leader for self-hosted. Workflows differ enough from GitHub to matter.

GitLab - production setup

EXAMPLE
# 1. Merge request - GitLab's PR equivalent
git checkout -b feat/login-form
# ... edit, commit, push ...
# Push prints a URL to open the MR; or use:
glab mr create --fill --target-branch=main


# 2. Protected branches
# Settings -> Repository -> Protected branches
# - main: only Maintainers can push
# - Disallow force push
# - Require approvals (CODEOWNERS supported)
# - Require at least N approvals from CODEOWNERS


# 3. CODEOWNERS
# Path-based ownership (similar to GitHub)
[Backend]
/src/api/        @backend-team
/src/db/         @data-team @backend-team

[Frontend]
/src/web/        @frontend-team


# 4. Pipelines - .gitlab-ci.yml
stages: [lint, test, build, deploy]

variables:
  NODE_VERSION: '20'

default:
  image: node:${NODE_VERSION}-alpine
  cache:
    key:
      files: [package-lock.json]
    paths: [node_modules/]

lint:
  stage: lint
  script:
    - npm ci
    - npm run lint

test:
  stage: test
  script:
    - npm ci
    - npm test -- --coverage
  coverage: '/^Statements\s+:\s(\d+\.\d+)%/'

build:
  stage: build
  script: [ 'npm ci', 'npm run build' ]
  artifacts:
    paths: [dist/]
    expire_in: 1 week

deploy:
  stage: deploy
  needs: [build]
  environment:
    name: production
    url: https://app.example.com
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'
  script: [ 'rsync ... ' ]


# 5. Environments + auto-deploys
# Define environments in CI to get review apps and stop-deploy controls.
# Review apps spin up per MR for preview.


# 6. Container registry, packages, dependency proxy - built in
# docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN
# docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA .
# docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA


# 7. glab - the unofficial GitHub CLI equivalent
# glab auth login
# glab mr list, glab mr view, glab pipeline status

# Useful CLI bits
glab mr checkout 42       # check out an MR locally
glab issue create
glab ci status

Why it matters

GitLab beats GitHub on tightly integrated CI + registry + environments. If you self-host or need review apps out of the box, GitLab is hard to argue with. Treat CODEOWNERS + protected branches as table stakes; treat environments + review apps as your superpower.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
# GitLab: built-in CI, Container Registry, Issue Boards.
glab repo create my-app
Try it Yourself »

Discussion

Loading…