Here is a comprehensive list of Git and GitLab CLI commands, covering basic usage, advanced operations, and configuration.
-
Check Git version:
git --version
-
Configure Git username and email:
git config --global user.name "Your Name" git config --global user.email "[email protected]"
-
Initialize a new Git repository:
git init
-
Clone a repository:
git clone REPOSITORY_URL
-
Check the status of the working directory:
git status
-
Add changes to the staging area:
git add FILE_NAME git add .
-
Commit changes to the repository:
git commit -m "Commit message"
-
View commit history:
git log
-
Show the difference between working directory and index:
git diff
-
Show the difference between index and last commit:
git diff --cached
-
List all branches:
git branch
-
Create a new branch:
git branch BRANCH_NAME
-
Switch to a branch:
git checkout BRANCH_NAME
-
Create and switch to a new branch:
git checkout -b BRANCH_NAME
-
Merge a branch into the current branch:
git merge BRANCH_NAME
-
Delete a branch:
git branch -d BRANCH_NAME
-
List all remote branches:
git branch -r
-
Add a remote repository:
git remote add REMOTE_NAME REPOSITORY_URL
-
List remote repositories:
git remote -v
-
Fetch changes from a remote repository:
git fetch REMOTE_NAME
-
Pull changes from a remote repository:
git pull REMOTE_NAME BRANCH_NAME
-
Push changes to a remote repository:
git push REMOTE_NAME BRANCH_NAME
-
Remove a remote repository:
git remote remove REMOTE_NAME
-
Rename a remote repository:
git remote rename OLD_NAME NEW_NAME
-
List all tags:
git tag
-
Create a new tag:
git tag TAG_NAME
-
Push a tag to a remote repository:
git push REMOTE_NAME TAG_NAME
-
Delete a tag:
git tag -d TAG_NAME
-
Stash changes:
git stash
-
List stashed changes:
git stash list
-
Apply the most recent stash:
git stash apply
-
Drop a stash:
git stash drop STASH@{0}
-
Clean untracked files and directories:
git clean -f git clean -fd
-
Show Git configuration:
git config --list
-
Edit Git configuration:
git config --global -e
-
Get help for a Git command:
git help COMMAND_NAME
GitLab primarily interacts through its API or Git commands. However, GitLab also provides a CLI tool (glab
) for easier interaction.
-
Install
glab
:# For macOS using Homebrew brew install glab # For Linux using a binary release curl -s https://api.github.com/repos/profclems/glab/releases/latest \ | grep "browser_download_url.*linux_amd64.tar.gz" \ | cut -d : -f 2,3 \ | tr -d \" \ | xargs curl -LO \ && tar xf glab_*_linux_amd64.tar.gz \ && sudo mv glab /usr/local/bin
-
Authenticate with GitLab:
glab auth login
-
List GitLab projects:
glab repo list
-
Create a new issue:
glab issue create -t "Issue Title" -d "Issue description"
-
List issues:
glab issue list
-
Show an issue:
glab issue view ISSUE_ID
-
Create a merge request:
glab mr create -t "Merge Request Title" -d "Merge request description"
-
List merge requests:
glab mr list
-
Show a merge request:
glab mr view MR_ID
-
Merge a merge request:
glab mr merge MR_ID
-
Delete a project:
glab repo delete PROJECT_NAME
-
Trigger a pipeline:
glab pipeline trigger --ref BRANCH_NAME
-
List pipelines:
glab pipeline list
-
Show pipeline details:
glab pipeline view PIPELINE_ID
This list covers essential Git and GitLab CLI commands for managing repositories, branches, remotes, and configurations. It also includes advanced commands for stashing, cleaning, and using GitLab’s CLI tool glab
for interacting with GitLab projects and issues. This comprehensive set of commands will help streamline version control and project management workflows.