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 →

Was it useful? Share this post with the world!

5 Replies to “Create GitLab Project/Repository from Command Line”

  1. Perfect!!
    I appreciate the succinct, quick and clear example. This is a perfect reference for a quick refresher.
    Thanks for your time!

  2. Thanks for sharing, I tried for ssh it’s didn’t worked maybe something changed after this guide.
    I use instead of this git push –set-upstream git@gitlab.com//gitlab-project.git command this one:
    git push –set-upstream git@gitlab.com:/gitlab-project.git

  3. Shahin – i followed your advice and it worked too.
    Thanks

  4. You really could create a new repository this way? Without creating it before on GitLab?
    I get the following error:
    “Please make sure you have the correct access rights and the repository exists.”
    To be clear:
    I created my repository local and tryed to push it to GitLab, expecting that the repository would be created on GitLab?
    Thanks, Mike

  5. Thanks a lot

Leave a Reply