GitLab CLI

GitLab CLI Cheatsheet #

GitLab CLI (GitLab Runner and GitLab CI/CD) provides commands to manage and interact with GitLab instances, repositories, CI/CD pipelines, and more directly from the command line.

General Commands #

Command/OptionExampleDescription
gitlab-rake gitlab:checksudo gitlab-rake gitlab:checkCheck GitLab configuration
gitlab-ctl reconfiguresudo gitlab-ctl reconfigureReconfigure GitLab instance
gitlab-ctl restartsudo gitlab-ctl restartRestart GitLab services
gitlab-ctl statussudo gitlab-ctl statusCheck the status of GitLab services

User Management #

Command/OptionExampleDescription
gitlab-rails consolesudo gitlab-rails consoleAccess the GitLab Rails console
user = User.find_by(email: ’email@example.com')user = User.find_by(email: 'email@example.com')Find a user by email in the Rails console
user.update!(admin: true)user.update!(admin: true)Promote a user to admin in the Rails console
user.destroyuser.destroyDelete a user in the Rails console

Project Management #

Command/OptionExampleDescription
gitlab project listgitlab project listList all projects
gitlab project creategitlab project create --name <project_name>Create a new project
gitlab project deletegitlab project delete --id <project_id>Delete a project
gitlab project archivegitlab project archive --id <project_id>Archive a project
gitlab project unarchivegitlab project unarchive --id <project_id>Unarchive a project

Repository Management #

Command/OptionExampleDescription
git clonegit clone <repository_url>Clone a repository
git pushgit push origin masterPush changes to the master branch
git pullgit pull origin masterPull changes from the master branch
git branchgit branch <branch_name>Create a new branch
git checkoutgit checkout <branch_name>Switch to a different branch

CI/CD Pipeline Management #

Command/OptionExampleDescription
gitlab-runner listgitlab-runner listList all registered runners
gitlab-runner registergitlab-runner registerRegister a new runner
gitlab-runner unregistergitlab-runner unregister --name <runner_name>Unregister a runner
gitlab-runner rungitlab-runner runRun the GitLab runner
gitlab-runner verifygitlab-runner verifyVerify all registered runners
gitlab-ci.ymlstages:\n - build\n - test\n - deploy\n\nbuild:\n stage: build\n script:\n - echo "Building..."Example .gitlab-ci.yml configuration for CI/CD pipelines

Merge Request Management #

Command/OptionExampleDescription
gitlab mr listgitlab mr listList all merge requests
gitlab mr creategitlab mr create --source-branch <branch> --target-branch <branch> --title <title>Create a new merge request
gitlab mr mergegitlab mr merge --id <mr_id>Merge a merge request
gitlab mr closegitlab mr close --id <mr_id>Close a merge request

Issue Management #

Command/OptionExampleDescription
gitlab issue listgitlab issue listList all issues
gitlab issue creategitlab issue create --title <title> --description <description>Create a new issue
gitlab issue closegitlab issue close --id <issue_id>Close an issue
gitlab issue reopengitlab issue reopen --id <issue_id>Reopen a closed issue

Group Management #

Command/OptionExampleDescription
gitlab group listgitlab group listList all groups
gitlab group creategitlab group create --name <group_name>Create a new group
gitlab group deletegitlab group delete --id <group_id>Delete a group
gitlab group add-membergitlab group add-member --group-id <group_id> --user-id <user_id> --access-level <access_level>Add a member to a group
gitlab group remove-membergitlab group remove-member --group-id <group_id> --user-id <user_id>Remove a member from a group

Backup and Restore #

Command/OptionExampleDescription
gitlab-backup createsudo gitlab-backup createCreate a backup of the GitLab instance
gitlab-backup restoresudo gitlab-backup restore BACKUP=<backup_file>Restore the GitLab instance from a backup

Log Management #

Command/OptionExampleDescription
gitlab-ctl tailsudo gitlab-ctl tailTail the GitLab logs
gitlab-ctl tailsudo gitlab-ctl tail nginxTail the logs of a specific GitLab service
gitlab-ctl reconfiguresudo gitlab-ctl reconfigureReconfigure GitLab services

This cheatsheet covers the most commonly used GitLab CLI commands and options, helping you to manage users, projects, repositories, CI/CD pipelines, merge requests, issues, groups, backups, and logs effectively.

GitLab CLI

Explore our comprehensive cheatsheets to enhance your knowledge and efficiency. Each cheatsheet provides detailed command options, examples, and descriptions to help you master various tools and technologies.