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/Option | Example | Description |
---|
gitlab-rake gitlab:check | sudo gitlab-rake gitlab:check | Check GitLab configuration |
gitlab-ctl reconfigure | sudo gitlab-ctl reconfigure | Reconfigure GitLab instance |
gitlab-ctl restart | sudo gitlab-ctl restart | Restart GitLab services |
gitlab-ctl status | sudo gitlab-ctl status | Check the status of GitLab services |
User Management
#
Command/Option | Example | Description |
---|
gitlab-rails console | sudo gitlab-rails console | Access 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.destroy | user.destroy | Delete a user in the Rails console |
Project Management
#
Command/Option | Example | Description |
---|
gitlab project list | gitlab project list | List all projects |
gitlab project create | gitlab project create --name <project_name> | Create a new project |
gitlab project delete | gitlab project delete --id <project_id> | Delete a project |
gitlab project archive | gitlab project archive --id <project_id> | Archive a project |
gitlab project unarchive | gitlab project unarchive --id <project_id> | Unarchive a project |
Repository Management
#
Command/Option | Example | Description |
---|
git clone | git clone <repository_url> | Clone a repository |
git push | git push origin master | Push changes to the master branch |
git pull | git pull origin master | Pull changes from the master branch |
git branch | git branch <branch_name> | Create a new branch |
git checkout | git checkout <branch_name> | Switch to a different branch |
CI/CD Pipeline Management
#
Command/Option | Example | Description |
---|
gitlab-runner list | gitlab-runner list | List all registered runners |
gitlab-runner register | gitlab-runner register | Register a new runner |
gitlab-runner unregister | gitlab-runner unregister --name <runner_name> | Unregister a runner |
gitlab-runner run | gitlab-runner run | Run the GitLab runner |
gitlab-runner verify | gitlab-runner verify | Verify all registered runners |
gitlab-ci.yml | stages:\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/Option | Example | Description |
---|
gitlab mr list | gitlab mr list | List all merge requests |
gitlab mr create | gitlab mr create --source-branch <branch> --target-branch <branch> --title <title> | Create a new merge request |
gitlab mr merge | gitlab mr merge --id <mr_id> | Merge a merge request |
gitlab mr close | gitlab mr close --id <mr_id> | Close a merge request |
Issue Management
#
Command/Option | Example | Description |
---|
gitlab issue list | gitlab issue list | List all issues |
gitlab issue create | gitlab issue create --title <title> --description <description> | Create a new issue |
gitlab issue close | gitlab issue close --id <issue_id> | Close an issue |
gitlab issue reopen | gitlab issue reopen --id <issue_id> | Reopen a closed issue |
Group Management
#
Command/Option | Example | Description |
---|
gitlab group list | gitlab group list | List all groups |
gitlab group create | gitlab group create --name <group_name> | Create a new group |
gitlab group delete | gitlab group delete --id <group_id> | Delete a group |
gitlab group add-member | gitlab group add-member --group-id <group_id> --user-id <user_id> --access-level <access_level> | Add a member to a group |
gitlab group remove-member | gitlab group remove-member --group-id <group_id> --user-id <user_id> | Remove a member from a group |
Backup and Restore
#
Command/Option | Example | Description |
---|
gitlab-backup create | sudo gitlab-backup create | Create a backup of the GitLab instance |
gitlab-backup restore | sudo gitlab-backup restore BACKUP=<backup_file> | Restore the GitLab instance from a backup |
Log Management
#
Command/Option | Example | Description |
---|
gitlab-ctl tail | sudo gitlab-ctl tail | Tail the GitLab logs |
gitlab-ctl tail | sudo gitlab-ctl tail nginx | Tail the logs of a specific GitLab service |
gitlab-ctl reconfigure | sudo gitlab-ctl reconfigure | Reconfigure 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.