There are many reasons one would prefer to work from the command line. Regardless of your reasons, here is how to use Git/GitLab using only command line tools.
Jump to a Section:
This guide is adapted from GitLab's documentation.
It is assumed that users of this guide understand basic Git/version control principles. To read more, visit this page.
First, use the command line to see if Git is installed.
To install or update Git using your package manager:
sudo yum install gitsudo yum update git
sudo apt-get install gitsudo apt-get update git
MacOS, use Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"brew install gitbrew upgrade git
Windows: download Git for Windows and install it.
Setup Git with your access credentials to GitLab with the following commands:
git config --global user.name "your_username"git config --global user.email "[email protected]"
You can review the information that you entered during set-up:
git config --global --list
(Optional) Consider adding your SSH key to your GitLab profile so you are not prompted for credentials after every commit. To add your public SSH key to GitLab:
Click on your user image in the top-right of the GitLab window.
On the left, click
Paste your public ssh key in the box, provide a title, and save by clicking
Clone an existing repository. In GitLab, this information is found on the "Overview" page of the repository.
git clone [email protected]:username/example-project.git
If you have already cloned the repository but are returning to your local version after a while, you'll want to make sure your local files are up to date with the branch. You can pull updates from master or branch_name.
git pull origin branch_name
You need to create a new branch or checkout an existing branch that can later be merged into the master branch. When naming branches, try to choose something descriptive.
To create a branch:
git checkout -b branch_name
To list existing branches:
git branch -r
To checkout an existing branch:
git checkout --track origin/branch_name or
git checkout branch_name
Note: You may only have one branch checked out at a time.
Make edits to the files with your favorite text editor. Save your changes.
Git places "added" files in a staging area as it is waiting for you finalize your changes.
git add --all
When you have added (or staged) all of your changes, committing them prepares them for the push to the remote branch.
git commit -m "descriptive text about your changes"
After committing the edits, you'll want to push the changes to GitLab. If the following produces an error, see below the code snippet for common solutions. The structure of this command is
git push <remote> <branch>.
git push --set-upstream origin branch_name or
git push -u origin branch_name
At this time, GitLab does not natively support submissions for merge requests via the command line.
You can send a merge request using the GitLab GUI.
From the left menu panel in Gitlab, select
Merge Request then the green
New merge request button.
Select your branch in the "Source Branch" side.
Target branch is master.
On the next screen the only thing needed is:
Assign to: < Project Owner, etc. >
Submit merge request.