8

I have some bare git repository on my filesystem where users do pull/push. I install gitea and can't find how to add it to gitea. Other git-management systems have something like "add repository from filesystem", "scan directory", etc. which added existing repo to system. How to add it in gitea?

AeroSun
  • 2,401
  • 2
  • 23
  • 46

2 Answers2

4

At the moment I migrate from Filesystem Repositorys to Gitea.

How this could be done is heavily discussed here (we used SSH), where I got the basis for my approach.

The following steps worked for me:

  1. Clone the repo.git folder to another location git clone path/to/repo.git

  2. Create an empty repo in Gitea. Either by hand or using the api

    curl \
      -X POST "http://localhost:3000/api/v1/user/repos" \
      -H "accept: application/json" \
      -H "Authorization: token MY_TOKEN*" \
      -H "Content-Type: application/json" \
      -d "{\"name\": \"REPO_NAME\"}" \
      -i
    
  3. Optionally transfer to a organization

    curl \
      -X POST "http://localhost:3000/api/v1/repos/CURRENT_OWNER/REPO_NAME/transfer" \
      -H "accept: application/json" \
      -H "Authorization: token MY_TOKEN*" \
      -H "Content-Type: application/json" \
      -d "{\"new_owner\": \"NEW_ORGANIZATION_OR_INDIVIDUAL\"}" \
      -i
    
  4. Push the repo to gitea

  • git remote add neworigin "http://localhost:3000/username/test.git"
  • git push neworigin --all
  • git push neworigin --tags

*https://docs.gitea.io/en-us/api-usage/

bilogic
  • 449
  • 3
  • 18
Lukas Weber
  • 455
  • 6
  • 13
  • 1
    Thanks for this answer, I think it will be more complete if a step to transfer to an organization is added. – bilogic Jan 31 '23 at 09:15
  • Thanks Lukas. You're a savior. I wrote a C# app, which reads the repository table from the old Gitea MsSql DB, and then using the gitea API creates the repositories in the new Gitea (with a MySql DB), transfers ownership to an organization, and then executes git commands to clone old repositories, add the new-origin and push to the new Gitea. Perfect. – Teo Bebekis May 02 '23 at 21:29
2

You can use the 'unadopted repositories' method (merged in this pull request as of sep 2020).

  1. Locate gitea's app.ini config file and find the values of APP_NAME (the user name) and the repositories ROOT.
    Let's assume your config looks like this:
APP_NAME = dinsdale
...
[repository]
ROOT = /usr/local/data/gitea-repositories
  1. cd to $REPO/$APP_NAME which for the config above will be: /usr/local/data/gitea-repositories/dinsdale and make a bare clone from each repo on your local file system:
cd /usr/local/data/gitea-repositories/dinsdale

git clone --bare /path/to/my/local/repo1
git clone --bare /path/to/my/local/repo2
..
git clone --bare /path/to/my/local/repo42
  1. Click your profile icon in the top right corner and select Site Administration -> tab Repositories -> click Unadopted Repositories.

  2. Leave the search field blank, and click the Search button. The 'unadopted' orphan folders that you added will be displayed below.

  3. For each repo click the Adopt Files button to import the orphaned repo.

To manually convert a regular repo to a bare one see How to convert a normal Git repository to a bare one?

ccpizza
  • 28,968
  • 18
  • 162
  • 169