Create GitLab Project/Repository from Command Line

In GitLab you can create a new project/repository not only through a user interface, but also from the command line.

When you create a new local Git repository and then push it to GitLab, if this repository doesn’t exit there, the corresponding project for it will be created automatically.

This short note shows how to create a new project/repository on GitLab from the command line.

Cool Tip: How to create a “Hello World” CI/CD pipeline in GitLab! Read more →

Create GitLab Project/Repository from Command Line

Create a new gitlab-project folder and initiate a Git repository inside it:

$ mkdir gitlab-project
$ cd gitlab-project
$ git init

Create some files and do the first commit:

$ touch .gitignore README.md
$ git add -A
$ git commit -m 'Initial commit'

Depending on a preferred communication protocol, push the repository to GitLab and set up a remote origin (replace <username> in the URLs with your username):

# for Git over HTTPS
$ git push --set-upstream https://gitlab.com/<username>/gitlab-project.git
$ git remote add origin https://gitlab.com/<username>/gitlab-project.git

# for Git over SSH
$ git push --set-upstream git@gitlab.com/<username>/gitlab-project.git
$ git remote add origin git@gitlab.com/<username>/gitlab-project.git

This will trigger the new GitLab project creation.

Cool Tip: Save username & password in Git credentials store! Read more →

Leave a Reply