43

I've got an existing repository on GitLab / GitHub. I want a duplicate of that under the same group with a different repo name.

Note: Thought the answers might be similar to another question, I was not able to find the said another question by googling, I'm guessing other users might be unable to do so either.

2

3 Answers 3

58

In gitlab there is functionality out of the box:

  1. Go to Settings -> General of existing project
  2. Last expanded panel Advanced contains Export button. Click it and then on the top of this page you can see info message Project export started. A download link will be sent by email.
  3. Check email. There is following message:

Project NAME_OF_YOUR_EXISTING_PROJECT was exported successfully.

The project export can be downloaded from: SOME_LINK

The download link will expire in 24 hours.

  1. Click SOME_LINK and then check the Downloads folder
  2. In the UI, click the + button at the top of the left sidebar and select `New project/repository
  3. Click the Import project box
  4. Click the button Gitlab export
  5. Click Choose file and select previously downloaded file *.tar.gz
  6. Click the button Import project
  7. Then you will see Import in progress label.
  8. DEAL
Sign up to request clarification or add additional context in comments.

6 Comments

By following your description I found out that the option Gitlab export on the Import project may be hidden on local GitLab instances. It can be activated in the Admin menu Admin Area > Settings > General > Visibility and access controls (docs.gitlab.com/ee/user/admin_area/settings/…).
Does this also clone all project settings (aka everything which is not git)?
@MichaelK I'm not sure, but you can check and describe in this thread your experience!
I just saw that newer gitlab installation shows, what gets exported and what not. Maybe we could add this list to the answer, but "edit queue is full" :-D The following items will be exported: Project and wiki repositories, Project uploads, Project configuration, excluding integrations, Issues with comments, merge requests with diffs and comments, labels, milestones, snippets, and other project entities, LFS objects, Issue Boards, Design Management files and data,
The following items will NOT be exported: Job logs and artifacts, Container registry images, CI variables, Pipeline triggers, Webhooks, Any encrypted tokens
|
26

Another easiest way is ...

You can import your existing repositories by providing the Git URL:

  1. From your GitLab dashboard click New project
  2. Switch to the Import project tab
  3. Click on the Repo by URL button
  4. Fill in the “Git repository URL” and the remaining project fields
  5. Click Create project to begin the import process
  6. Once complete, you will be redirected to your newly created project

https://docs.gitlab.com/ee/user/project/import/repo_by_url.html

5 Comments

The easiest one.
Does this copy the repository settings?
Does this copy all of the branches?
It works perfectly. It doesn't copy any settings of the repository but it copies all of the branches (commits, tags, pipelines...).
For my company GitLab server, it seems that the Repository by URL import source is not enabled. In that case, this procedure does not work.
26

Duplicating a repository

To duplicate a repository without forking it, you can run a special clone command, then mirror-push to the new repository.

Before you can duplicate a repository and push to your new copy, or mirror, of the repository, you must create the new repository on GitHub/Gitlab. In these examples, exampleuser/new-repository is the mirrors.

Mirroring a repository

1. Open (windows) Git Bash

You can use (mac)Terminal / (linux)Terminal as well

2. Create a bare clone of the repository.

git clone --bare https://github.com/_exampleuser_/_old-repository_.git

3. Mirror-push to the new repository.

cd _old-repository_.git
git push --mirror https://github.com/_exampleuser_/_new-repository_.git

4. Remove the temporary local repository you created in step 2.

cd ..
rm -rf _old-repository_

reference: https://help.github.com/articles/duplicating-a-repository/

4 Comments

I realize this is an old post. I tried your suggestion, but when I got to step 3, the push was rejected with this error message: ! [remote rejected] master -> master (pre-receive hook declined) What might be causing this?
@LND Perhaps your master branch is still protected? You need to remove the protection to be able to overwrite it.
@JoepBeusenberg The master branch is unprotected. I retried and still got the same error message.
This does not copy the repository settings in GitLab.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.