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 email@example.com/<username>/gitlab-project.git $ git remote add origin firstname.lastname@example.org/<username>/gitlab-project.git
This will trigger the new GitLab project creation.
Cool Tip: Save username & password in Git credentials store! Read more →
5 Replies to “Create GitLab Project/Repository from Command Line”
I appreciate the succinct, quick and clear example. This is a perfect reference for a quick refresher.
Thanks for your time!
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 email@example.com//gitlab-project.git command this one:
git push –set-upstream firstname.lastname@example.org:/gitlab-project.git
Shahin – i followed your advice and it worked too.
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 a lot