Create a repo in Gitlab using CLI

Since you just wanted to create a repo, there is no need of third party apps. You can directly send a post request to gitlab API which will create repo.

Go to account tab in your profile, you will find a private token. Copy that.

Now open terminal and run this command with private token (say foo) and your repo name (say bar).

curl -H "Content-Type:application/json" https://gitlab.com/api/v4/projects?private_token=foo -d "{ \"name\": \"bar\" }"

For convenience, you can create a shell script, if you don't want to run this command every time.

#!/bin/sh

curl -H "Content-Type:application/json" https://gitlab.com/api/v4/projects?private_token=foo -d "{ \"name\": \"$1\" }"

Save this to a file gcr.sh and make it executable using chmod +x gcr.sh.

Now to create a repo name bar, run

$ ./gcr.sh bar

gitlab-cli is no longer maintained, the author references the Gitlab module to be used instead - it also includes a CLI tool.

For your specific request - namely creating a project on the command line, use the following command:

gitlab create_project "YOUR_PROJECT_NAME" "{namespace_id: 'YOUR_NUMERIC_GROUP_ID'}"

Be sure to use the option namespace_id and not group_id! If you are not sure what your GROUP_ID is, you can use

gitlab groups | grep YOUR_GROUP_NAME

to find out.

The parameters for each command can be inferred from the API documentation. Any non-scalar valued parameter has to be encoded in an inline YAML syntax (as above).

Tags:

Git

Ssh

Gitlab