Corona
Corona

Reputation: 81

How to set up a default repository in GitLab

I would like to set up a default repository in GitLab that comes with every new project. So when I check out the new project, I am not checking out an empty repo, but one filled up with my default project folders and files.

Anyone knows how to do this?

Upvotes: 2

Views: 1549

Answers (1)

BrokenBinary
BrokenBinary

Reputation: 7889

Option 1

You could setup a base project with all your default folders and files, and then clone that project as the first step in every new project. After cloning it, change the remote to point to a new remote repo and push to it.

The workflow would look like this:

  1. Create the new project on GitLab and copy the clone URL.
  2. Clone the base project into a new directory and navigate to that directory.
  3. Change the remote URL to point to your new project's clone URL.
  4. Push the master branch to the new repo.

The commands for that would be:

git clone https://gitlab.com/username/base-project new-project
cd new-project
git remote set-url origin https://gitlab.com/username/new-project
git push -u origin master

Option 2

You could fork each new project off of a base project. This has the benefit that it can be done entirely in the GitLab UI. The base project will have to be in a separate namespace (username or group) though, because GitLab won't let you fork a project into the same namespace as the original project.

The workflow would look like this:

  1. Fork the base project.
  2. Go the settings of the new project and break the fork relationship. You're never going to merge this project back into the base project, so you don't need it.
  3. Rename the new project.

Option 3

Prior to GitLab v8.6.0 this method would expose the full URL of the repo being imported in the logs. If you import from a private repo and put your username/password in the URL they will be readable in plaintext in the log files. See this issue for more info.

You could import the base project as a new project every time. This also has the benefit that it can be done entirely in the GitLab UI, and you can rename the project before starting the import, so you don't have to worry about having another namespace like in option 2. This method works best if your GitLab instance allows importing from any repo URL.

The workflow would look like this:

  1. Copy the HTTPS clone URL of the base repo.
  2. Click on "New Project" in GitLab and select the option to "Import Project from any repo by URL"
  3. Paste in the URL of the base repo. If your base repo is not publicly available then you'll need to add your username/password to the URL like this: https://username:[email protected]/username/base-project.git.

Note that if you have to include your password in the import URL, and your username or password has an @ symbol in it, you'll have to url encode it. So p@ssword would become p%40ssword.

Upvotes: 2

Related Questions