GitLab Cheat Sheet
Table of Contents
Account Management
Project Management
Repository Operations
Issues and Merge Requests
CI/CD
GitLab Pages
GitLab Runner
Collaboration Features
GitLab Security
GitLab API
Best Practices
Account Management
Create a new account
Go to https://gitlab.com
Click "Register now"
Fill in your details and click "Register"
Enable two-factor authentication (2FA)
Go to Settings > Account
Scroll to "Two-Factor Authentication" section
Click "Enable two-factor authentication"
Add an SSH key
Generate an SSH key pair
ssh-keygen -t ed25519 -C "your_email@example.com"
Go to Settings > SSH Keys
Paste your public key and click "Add key"
Project Management
Create a new project
Click "New project" on your dashboard
Choose "Create blank project"
Fill in project details and click "Create project"
Import a project
Click "New project" on your dashboard
Choose "Import project"
Select the source (e.g., GitHub, Bitbucket) and follow the prompts
Create a group
Click "Groups" in the top menu
Click "New group"
Fill in group details and click "Create group"
Repository Operations
Clone a repository
git clone https://gitlab.com/username/repository.git
Create a new branch
git checkout -b new-branch-name
Push changes to GitLab
git push origin branch-name
Create a merge request from the command line
git push -u origin branch-name
gitlab mr create --source-branch branch-name --target-branch main
Issues and Merge Requests
Create a new issue
Go to your project's "Issues" page
Click "New issue"
Fill in the title and description
Click "Submit issue"
Create a merge request
Go to your project's "Merge Requests" page
Click "New merge request"
Select the source and target branches
Fill in the title and description
Click "Submit merge request"
Review a merge request
Go to the "Merge Requests" page
Click on the merge request you want to review
Leave comments, approve, or request changes
Resolve merge conflicts
In the merge request, click "Resolve conflicts"
Edit the conflicting files
Stage the changes and commit
Push the changes to resolve the conflicts
CI/CD
Set up CI/CD
Create a .gitlab-ci.yml file in your repository root
Define your pipeline stages and jobs
Example .gitlab-ci.yml:
stages :
- build
- test
- deploy
build_job :
stage : build
script :
- echo "Building the project... "
test_job :
stage : test
script :
- echo "Running tests... "
deploy_job :
stage : deploy
script :
- echo "Deploying to production... "
only :
- main
View pipeline results
Go to your project's "CI/CD > Pipelines" page
Click on a pipeline to see its details and job logs
GitLab Pages
Enable GitLab Pages
Create a .gitlab-ci.yml file in your repository
Add a job that generates your static site
Example for a Jekyll site:
pages :
stage : deploy
script :
- bundle exec jekyll build - d public
artifacts :
paths :
- public
only :
- main
Access your GitLab Pages site
GitLab Runner
Install GitLab Runner
Register a runner
gitlab-runner register
Start the runner
gitlab-runner start
Collaboration Features
Add project members
Go to your project's "Settings > Members"
Click "Invite members"
Enter the user's name or email and select their role
Create a team
Go to your group's page
Click "Subgroups and projects"
Click "New subgroup" to create a team
Code review settings
Go to your project's "Settings > Merge requests"
Configure approval rules and other merge request settings
GitLab Security
Enable Dependency Scanning
Go to "Security & Compliance > Configuration"
Enable "Dependency Scanning"
Set up Container Scanning
Go to "Security & Compliance > Configuration"
Enable "Container Scanning"
Create a security policy
Create a SECURITY.md file in your repository
Define your security policy and vulnerability reporting process
GitLab API
Generate a personal access token
Go to Settings > Access Tokens
Create a new token with the necessary scopes
Make an API request
Using curl:
curl --header "PRIVATE-TOKEN: your_access_token" "https://gitlab.com/api/v4/projects"
Using Python requests:
import requests
url = "https://gitlab.com/api/v4/projects"
headers = { "PRIVATE-TOKEN" : "your_access_token" }
response = requests. get( url, headers= headers)
print ( response. json( ) )
Best Practices
Use meaningful commit messages : Write clear, concise commit messages that explain the changes made.
Utilize merge request templates : Create templates for merge requests to ensure consistent and comprehensive descriptions.
Leverage GitLab CI/CD : Automate your testing, building, and deployment processes using GitLab CI/CD pipelines.
Use GitLab Issues for project management : Organize your work using issues, labels, milestones, and boards.
Implement code review guidelines : Establish and follow code review best practices within your team.
Utilize GitLab Wiki : Document your project thoroughly using GitLab's built-in Wiki feature.
Regular backups : Use GitLab's backup features to ensure your data is safe and recoverable.
Monitor your GitLab instance : If self-hosting, use GitLab's monitoring tools to keep track of your instance's health.
Use merge request approvals : Set up approval rules to ensure code quality and security.
Leverage GitLab's built-in security features : Utilize features like SAST, dependency scanning, and container scanning to improve your project's security.