0

Since I have more than 100 projects to be created in Gitlab, is there a way that creation till push to repository can be automated. Create project->Clone the repo.->Push modified files. This flow needs to be automated. Please provide me reference incase of no specifics.

2
  • What exactly are you trying to do? Are you migrating from one place to another? Such as from github.com to gitlab.com? 18 hours ago
  • @AdamMarshall no, I am just creating multiple java services and have to host them on gitlab. I need scripts which can ease my process of creating project, cloning and pushing them back in complete automated way.
    – Meenal
    17 hours ago

1 Answer 1

0

Projects don't have to be created in advance. You can just push to any namespace to create projects.

git remote add origin ssh://git@gitlab.example.com/mynamespace/my-newproject.git
git push -u origin --all

You'll see the server respond back with a message like this:

remote: The private project mynamespace/my-newprojct was successfully created.

If you wanted a script to create a project from scratch, you might do something like this:

#!/usr/bin/env bash
# create-project.sh
gitlab_host="gitlab.example.com"  # replace with your host
project_path=$1
project_name="$(basename "${project_path}")"
mkdir "$project_name"
pushd "$project_name"
echo "# ${project_name}" > README.md
# Put any additional project file creation steps here
git init
git checkout -b main
git add .
git commit -m "initial commit"
git remote add origin "ssh://git@${gitlab_host}/${project_path}.git"
git push -u origin main
popd

Usage:

./create-project.sh mynamespace/my-newproject

This will create a directory my-newproject, setup repo files, remote, and push it to GitLab creating the project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.