2020-10-30 17:08:52 -04:00
---
stage: none
group: unassigned
2020-11-26 01:09:20 -05:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-10-30 17:08:52 -04:00
---
2020-04-28 20:09:38 -04:00
# Import bare repositories **(CORE ONLY)**
2014-04-30 09:02:37 -04:00
2020-04-27 02:09:51 -04:00
Rake tasks are available to import bare repositories into a GitLab instance.
2020-09-01 11:10:39 -04:00
When migrating from an existing GitLab instance,
and to preserve ownership by users and their namespaces,
please use [our project-based import/export ](../user/project/settings/import_export.md ).
2014-04-30 09:02:37 -04:00
2020-04-27 02:09:51 -04:00
Note that:
2014-04-30 09:02:37 -04:00
2020-11-19 22:09:15 -05:00
- The owner of the project is the first administrator.
- The groups are created as needed, including subgroups.
- The owner of the group is the first administrator.
- Existing projects are skipped.
2020-04-27 02:09:51 -04:00
- Projects in hashed storage may be skipped. For more information, see
[Importing bare repositories from hashed storage ](#importing-bare-repositories-from-hashed-storage ).
2020-11-19 22:09:15 -05:00
- The existing Git repositories ware moved from disk (removed from the original path).
2014-04-30 09:02:37 -04:00
2020-04-27 02:09:51 -04:00
To import bare repositories into a GitLab instance:
2014-10-29 18:21:55 -04:00
2020-09-01 11:10:39 -04:00
1. Create a new folder to import your Git repositories from.
You can also import projects into a (sub)group's namespace,
instead of the administrator's namespace. To do so, create subfolders and
give ownership and read/write/execute permissions of those subfolders to the
`git` user and its group:
2015-01-16 22:36:44 -05:00
2020-04-27 02:09:51 -04:00
```shell
2020-09-01 11:10:39 -04:00
sudo -u git mkdir -p /var/opt/gitlab/git-data/repository-import-$(date "+%Y-%m-%d")/< optional_groupname > /< optional_subgroup >
2020-04-27 02:09:51 -04:00
```
2014-04-30 09:02:37 -04:00
2020-04-27 02:09:51 -04:00
1. Copy your bare repositories inside this newly created folder. Note:
2017-11-07 14:11:42 -05:00
2020-11-19 22:09:15 -05:00
- Any `.git` repositories found on any of the subfolders are imported as projects.
- Groups are created as needed, these could be nested folders.
2017-11-07 14:11:42 -05:00
2020-09-01 11:10:39 -04:00
For example, if we copy the repositories to `/var/opt/gitlab/git-data/repository-import-2020-08-22` ,
2020-04-27 02:09:51 -04:00
and repository `A` needs to be under the groups `G1` and `G2` , it must be created under those folders:
2020-09-01 11:10:39 -04:00
`/var/opt/gitlab/git-data/repository-import-2020-08-22/G1/G2/A.git` .
2015-01-21 09:14:46 -05:00
2020-04-27 02:09:51 -04:00
```shell
2020-09-01 11:10:39 -04:00
sudo cp -r /old/git/foo.git /var/opt/gitlab/git-data/repository-import-$(date "+%Y-%m-%d")/< optional_groupname > /< optional_subgroup >
2014-10-29 18:21:55 -04:00
2020-04-27 02:09:51 -04:00
# Do this once when you are done copying git repositories
2020-09-01 11:10:39 -04:00
sudo chown -R git:git /var/opt/gitlab/git-data/repository-import-$(date "+%Y-%m-%d")
2020-04-27 02:09:51 -04:00
```
2015-01-16 22:36:44 -05:00
2020-04-27 02:09:51 -04:00
`foo.git` needs to be owned by the `git` user and `git` users group.
2015-01-26 11:03:04 -05:00
2020-04-27 02:09:51 -04:00
If you are using an installation from source, replace `/var/opt/gitlab/` with `/home/git` .
2014-10-29 18:21:55 -04:00
2020-04-27 02:09:51 -04:00
1. Run the following command depending on your type of installation:
2014-10-29 18:21:55 -04:00
2020-04-27 02:09:51 -04:00
- Omnibus Installation
2014-06-23 04:38:22 -04:00
2020-04-27 02:09:51 -04:00
```shell
2020-09-01 11:10:39 -04:00
sudo gitlab-rake gitlab:import:repos['/var/opt/gitlab/git-data/repository-import-$(date "+%Y-%m-%d")']
2020-04-27 02:09:51 -04:00
```
2014-10-29 18:21:55 -04:00
2020-04-27 02:09:51 -04:00
- Installation from source. Before running this command you need to change to the directory where
your GitLab installation is located:
2014-10-30 13:38:09 -04:00
2020-04-27 02:09:51 -04:00
```shell
cd /home/git/gitlab
2020-09-01 11:10:39 -04:00
sudo -u git -H bundle exec rake gitlab:import:repos['/var/opt/gitlab/git-data/repository-import-$(date "+%Y-%m-%d")'] RAILS_ENV=production
2020-04-27 02:09:51 -04:00
```
2014-04-30 09:02:37 -04:00
2020-04-27 02:09:51 -04:00
## Example output
2014-04-30 09:02:37 -04:00
2020-03-02 22:08:31 -05:00
```plaintext
2017-11-07 14:11:42 -05:00
Processing /var/opt/gitlab/git-data/repository-import-1/a/b/c/blah.git
* Using namespace: a/b/c
* Created blah (a/b/c/blah)
* Skipping repo /var/opt/gitlab/git-data/repository-import-1/a/b/c/blah.wiki.git
Processing /var/opt/gitlab/git-data/repository-import-1/abcd.git
2014-04-30 09:02:37 -04:00
* Created abcd (abcd.git)
2017-11-07 14:11:42 -05:00
Processing /var/opt/gitlab/git-data/repository-import-1/group/xyz.git
* Using namespace: group (2)
2014-04-30 09:02:37 -04:00
* Created xyz (group/xyz.git)
2017-11-07 14:11:42 -05:00
* Skipping repo /var/opt/gitlab/git-data/repository-import-1/@shared/a/b/abcd.git
2014-04-30 09:02:37 -04:00
[...]
```
2018-11-02 18:59:09 -04:00
## Importing bare repositories from hashed storage
Projects in legacy storage have a directory structure that mirrors their full
project path in GitLab, including their namespace structure. This information is
leveraged by the bare repository importer to import projects into their proper
locations. Each project and its parent namespaces are meaningfully named.
However, the directory structure of projects in hashed storage do not contain
this information. This is beneficial for a variety of reasons, especially
improved performance and data integrity. See
[Repository Storage Types ](../administration/repository_storage_types.md ) for
more details.
2020-04-27 02:09:51 -04:00
The repositories that are importable depends on the version of GitLab.
2018-11-02 18:59:09 -04:00
2020-04-27 02:09:51 -04:00
### GitLab 10.3 or earlier
2018-11-02 18:59:09 -04:00
Importing bare repositories from hashed storage is unsupported.
2020-04-27 02:09:51 -04:00
### GitLab 10.4 and later
2018-11-02 18:59:09 -04:00
2018-11-07 15:52:18 -05:00
To support importing bare repositories from hashed storage, GitLab 10.4 and
later stores the full project path with each repository, in a special section of
2020-04-27 02:09:51 -04:00
the Git repository's configuration file. This section is formatted as follows:
2018-11-07 15:40:07 -05:00
2020-03-03 22:08:50 -05:00
```ini
2018-11-07 15:40:07 -05:00
[gitlab]
2019-09-18 14:06:14 -04:00
fullpath = gitlab-org/gitlab
2018-11-07 15:40:07 -05:00
```
However, existing repositories were not migrated to include this path.
2018-11-02 18:59:09 -04:00
2018-11-07 15:52:18 -05:00
Bare repositories are importable if the following events occurred to the
repository in GitLab 10.4 and later:
2018-11-02 18:59:09 -04:00
2018-11-07 15:52:18 -05:00
- Created
- Migrated to hashed storage
- Renamed
- Transferred to another namespace
- Ancestor renamed
- Ancestor transferred to another namespace
2018-11-02 18:59:09 -04:00
2020-05-28 08:08:10 -04:00
Bare repositories are **not** importable by GitLab 10.4 to GitLab 11.6, if all the following are true about the repository:
2018-11-02 18:59:09 -04:00
2018-11-07 15:52:18 -05:00
- It was created in GitLab 10.3 or earlier.
2020-05-28 08:08:10 -04:00
- It was not renamed, transferred, or migrated to [hashed storage ](../administration/repository_storage_types.md#hashed-storage ) in GitLab 10.4 to GitLab 11.6.
- Its ancestor namespaces were not renamed or transferred in GitLab 10.4 to GitLab 11.6.
2018-11-02 18:59:09 -04:00
2020-10-14 20:08:42 -04:00
[In GitLab 11.6 ](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/41776 ) and later, all
2020-05-28 08:08:10 -04:00
bare repositories are importable.
2018-11-07 15:32:23 -05:00
2020-05-28 08:08:10 -04:00
To manually migrate repositories yourself (for GitLab 10.4 to GitLab 11.6), you can use the
2020-10-14 11:08:42 -04:00
[Rails console ](../administration/operations/rails_console.md#starting-a-rails-console-session )
2018-11-07 15:32:23 -05:00
to do so. In a Rails console session, run the following to migrate a project:
2020-03-03 22:08:50 -05:00
```ruby
2019-09-18 14:06:14 -04:00
project = Project.find_by_full_path('gitlab-org/gitlab')
2018-11-07 15:32:23 -05:00
project.write_repository_config
```
In a Rails console session, run the following to migrate all of a namespace's
2018-11-07 15:52:18 -05:00
projects (this may take a while if there are 1000s of projects in a namespace):
2018-11-07 15:32:23 -05:00
2020-03-03 22:08:50 -05:00
```ruby
2018-11-07 15:32:23 -05:00
namespace = Namespace.find_by_full_path('gitlab-org')
namespace.send(:write_projects_repository_config)
2018-11-07 15:52:18 -05:00
```