In comparison with the prior answers by ChillarAnand and eigenfield, although this answer too uses the REST API with curl
, it also:
- authorizes against GitLab by providing the token in the header, not in the URL
- makes
curl
exit with a nonzero code in case of an error (via-f
) - uses the
path
parameter instead of thename
parameter, thereby avoiding the risk of a dissimilar path from being used
First, obtain a token with access to the api
scope.
REPO_NAME=foo1GITLAB_TOKEN=xxxxxxxxxxxxxxxxxxxx # Enter your own.curl -f -X POST \ -H "PRIVATE-TOKEN: ${GITLAB_TOKEN}" -H "Content-Type:application/json" \"https://gitlab.com/api/v4/projects" -d "{\"path\": \"${REPO}\", \"visibility\": \"private\"}"
This answer is relevant only for creating a repository as a user. The request for creating a repository as an admin is different.
As an aside, explicitly creating the repo is optional, since GitLab is known to be capable of creating the repo on first push. (credit: Elan R.)