Repository: A centralized storage location for code, files, and version history.
Browse / GitLab Cheat Sheet
GitLab Cheat Sheet
A comprehensive cheat sheet for using GitLab, covering essential commands, features, and workflows for version control and collaboration.
GitLab Basics
Core Concepts
|
|
|
Branch: An independent line of development, allowing for parallel work and feature isolation. |
|
Merge Request (MR): A proposal to merge changes from one branch into another. It includes code review, discussions, and automated checks. |
|
Pipeline: An automated workflow that defines the steps required to build, test, and deploy code. |
|
CI/CD: Continuous Integration and Continuous Delivery/Deployment. A set of practices to automate the software release process. |
GitLab Workflow
|
|
|
|
|
|
|
Basic Git Commands
|
`git clone ` |
Clone a repository from GitLab to your local machine. |
|
`git checkout -b ` |
Create and switch to a new branch. |
|
`git add .` |
Stage all changes for commit. |
|
`git commit -m ""` |
Commit staged changes with a descriptive message. |
|
`git push origin ` |
Push the local branch to the remote GitLab repository. |
|
`git pull origin ` |
Pull the latest changes from the remote branch to your local branch. |
Merge Requests & Code Review
Creating Merge Requests
|
|
|
|
|
Code Review Process
|
|
|
|
|
Merge Request Commands
|
`git fetch origin ` |
Fetch the remote branch to your local machine. |
|
`git merge origin/` |
Merge the remote branch into your current branch (after fetching). |
|
`git rebase origin/` |
Rebase your current branch onto the remote branch (alternative to merging). |
GitLab CI/CD
CI/CD Pipeline Configuration
|
GitLab CI/CD is configured using a |
|
Stages: Define the order in which jobs are executed (e.g., build, test, deploy). |
|
Jobs: Define the tasks to be performed in each stage (e.g., compiling code, running tests, deploying to a server). |
|
Scripts: Define the commands to be executed within each job. |
|
Variables: Define environment variables that can be used in your scripts. |
Example .gitlab-ci.yml
|
```yaml
build_job:
test_job:
deploy_job:
|
CI/CD Variables
|
`CI_COMMIT_BRANCH` |
The branch or tag name for which the pipeline is running. |
|
`CI_COMMIT_SHA` |
The commit SHA for which the pipeline is running. |
|
`CI_PROJECT_ID` |
The ID of the GitLab project. |
|
`CI_PROJECT_NAME` |
The name of the GitLab project. |
|
`CI_PIPELINE_ID` |
The ID of the current pipeline. |
GitLab Advanced Features
GitLab Pages
|
GitLab Pages allows you to host static websites directly from your GitLab repository. You can use it to create personal or project websites, documentation, or blogs. |
|
To set up GitLab Pages, you need to create a |
|
GitLab will automatically deploy your website to a GitLab Pages domain (e.g., |
GitLab Issues
|
GitLab Issues are used to track bugs, feature requests, and other tasks related to your project. They provide a central place to discuss and manage work. |
|
You can assign issues to team members, set milestones, add labels, and track progress. |
|
Issues can be linked to merge requests to track the code changes that address them. |
GitLab Security
|
GitLab provides various security features to help you identify and address vulnerabilities in your code. |
|
Static Application Security Testing (SAST): Analyzes your source code for potential vulnerabilities. |
|
Dynamic Application Security Testing (DAST): Tests your running application for vulnerabilities. |
|
Dependency Scanning: Identifies vulnerabilities in your project’s dependencies. |
|
Container Scanning: Scans your Docker images for vulnerabilities. |