DEV Community

Wen Ping
Wen Ping

Posted on Originally published at anguskit.com

Import a Git repository: enter one source URL and get the default branch

This article explains what AngusGit keeps when you import a public repository from one source URL, and when you should push the repository instead. After reading it, you can open Import repository, finish the import, and check that the result is only the files that were on the default branch plus one new commit; when the source is private, or you need the full history, the other branches, and the tags, you create an empty repository and push it with git clone --bare.

Sign in to AngusGit first. Import is at the top right of Repositories in the sidebar. To clone the private repository after import, or to push and keep history, prepare credentials first. For SSH, if this machine has no ~/.ssh/id_ed25519.pub, run ssh-keygen -t ed25519 -C "you@example.com", press Enter for the path, run cat ~/.ssh/id_ed25519.pub, and paste the whole line that starts with ssh-ed25519 into Add SSH Key under Settings → Profile, on the SSH Keys tab. The address is ssh://git@host:2222/owner/repo.git, and the username is git. For HTTPS, open Settings → Profile, the Access Tokens tab, and click Generate New Token. Enter your current login password. To clone only, select git:read and set the repository permission to READ. To push, select git:write and set it to WRITE. Copy the token immediately. The username is your AngusGit login name, and the password is the token.

The example is a real import on git.anguskit.com. The source URL is https://github.com/octocat/Hello-World.git. The owner is the signed-in account Angus / xlliu. The repository name is hello-world-import. Make this repository private is on. After the import, the code page is https://git.anguskit.com/code/xlliu/hello-world-import.

anguskit/AngusRepo is already on this instance. It is the artifact-repository product's own repository, and it was not imported from GitHub. Importing that name again shows Repository "anguskit/AngusRepo" already exists.

1. What an import brings over

Before you start, decide whether import is enough. The first two columns are the import rules. The last column is what the Hello-World import actually showed.

Item Brought over? What Hello-World showed
Every file on the source default branch at that moment Yes Only README, 13 B, containing Hello World!
The old commit history No One commit. The message is Initial commit from https://github.com/octocat/Hello-World.git. The short hash (the first characters of the commit id) is 25861fe
Branches other than the default branch No The Branches tab shows 1, and the name is main
Tags No Tags 0, Releases 0
Submodules No Hello-World has no submodules
Issues, pull requests, Wiki, CI, and member permissions No Issues 0, Wiki 0
New commits made on the source after the import Not synced automatically Import runs once

A pull request is a request to merge one branch into another after someone looks at the change. GitHub calls it a pull request. GitLab calls the same thing a merge request. AngusGit's label is Pull Requests. An import does not bring those over.

One more detail: Hello-World's default branch on GitHub is named master. The files are all there after import, but the branch name on AngusGit is the platform default, main. The name master is not kept.

Import fits when you only need the current version of the code. Two examples are taking an open-source project for internal follow-up work, and an old repository whose history does not matter. To keep every commit, or to bring other branches and tags, go to section 5.

2. Check two things before you import

First, the source repository must be readable without signing in. Visibility decides who can see a repository. The import form has no field for a source username or token, so AngusGit fetches the code anonymously. A public repository works. A private repository fails on submit with Source repository URL "…" is invalid or inaccessible. Do not put a username or token into the URL to get around this. That address is copied as-is into the commit message the import creates, and everyone who can see the new repository can read it. For a private source, use the push steps in section 5.

Second, the server running AngusGit must be able to reach the source site. The server does the fetch. Your own computer's internet access does not matter. If an intranet server cannot reach github.com, the import fails the same way. To check ahead of time, run git ls-remote <source-url> on that server. The command lists the source branches. If it prints them, the network path works. Hello-World could be imported, so that server could reach github.com at the time.

3. Import one repository

  • Open the import page

In the sidebar, click Repositories, then Import at the top right. The form is a full page. The title is Import repository. The line under it says "Import an existing repository from another version control system".

  • Enter the source URL

In Repository URL, paste the HTTPS clone URL. For Hello-World that is https://github.com/octocat/Hello-World.git. The hint says "Supports GitHub, GitLab, Gitee, SourceForge, and more". If the address does not start with https://, http://, or git@, the field shows Please enter a valid repository URL.

  • Choose the owner and enter the name

Owner defaults to the signed-in account. The list also includes teams where you are a maintainer. The example keeps the default Angus / xlliu. Repository name is not filled in from the URL. Type it yourself. The example uses hello-world-import, and the field shows the namespace prefix xlliu /. A name can use Chinese characters, letters, numbers, hyphens, and underscores. A dot you type is removed. Description can stay empty. The example leaves it empty. The gray text "Repository imported from GitHub" is placeholder text, not a value that was already saved.

  • Choose private or not

Make this repository private is off by default. Turn it on when only the team should see the code. The example turns it on, so the imported repository is private.

  • Start the import

Begin import can be clicked after Repository URL, Owner, and Repository name are filled in. After the click, the button stays disabled until the code has been fetched. A larger repository takes longer. Leave the page open. When the import finishes, the form closes and the new repository appears in the repository list. Hello-World is small, so the list comes back quickly.

The import form filled in: Repository URL is Hello-World, owner is Angus / xlliu, name is hello-world-import, and the private switch is on

The picture is the form before Begin import. The description is empty, and the private switch is already on.

4. Check the result: the code page has one commit

After the import, open the repository code page. For the example that is https://git.anguskit.com/code/xlliu/hello-world-import. The header badge says Private. The tabs show Branches 1, Tags 0, Releases 0, Issues 0, and Wiki 0. The branch selector shows main, with 1 Commit beside it. The author of that commit is Angus. The message is Initial commit from https://github.com/octocat/Hello-World.git. The short hash is 25861fe. The file list has one file, README, 13 B.

Private repository hello-world-import: one initial commit on main, and the only file is README

To clone, click the orange Code button at the top right. The panel heading is Clone. Under the HTTPS tab the note says "Clone using the web URL." The address is:

https://git.anguskit.com/xlliu/hello-world-import.git
Enter fullscreen mode Exit fullscreen mode

The SSH tab address is:

ssh://git@git.anguskit.com:2222/xlliu/hello-world-import.git
Enter fullscreen mode Exit fullscreen mode

Because the repository is private, clone asks for a username and an access token. The username is your AngusGit login name, and the password is the token from the start of this article: git:read to clone only, git:write to push. Do not put the token in a page or a screenshot. The check is done when the code page shows one initial commit and one file.

After the import, the team should pull code from AngusGit. In a local repository that still points at GitHub, git remote set-url origin <new-url> switches the remote to AngusGit. The new history does not match the source, so git push from the old local copy is rejected. The reliable approach is for each person to clone a fresh copy.

5. Keep the full history, or the source is private

In either of those cases, Import repository is not enough. Push instead. Clone the whole source on your computer, then push it to a new empty repository on AngusGit. Every branch, tag, and commit goes with it.

The target name hello-world-history in the commands below is only an example. Create that empty repository on AngusGit before you push. Do not push to the imported xlliu/hello-world-import. The histories do not match, so the push is rejected.

  • Create an empty repository on AngusGit

Follow the New repository steps. Leave Add a README file, Add .gitignore, and Choose a license unchecked. That is what makes the repository empty. If any box is checked, the push is rejected because the histories do not match. Copy the empty repository's URL when it exists.

  • Clone the whole source locally

git clone --bare creates a bare repository. A bare repository stores only Git data: every branch, tag, and commit. It does not create working files you can edit, which is what you want when you are forwarding the repository unchanged. A private source asks you to sign in to the source site at this step.

  • Rename the main branch when it is not main

A new empty repository on AngusGit uses main as the default branch. Hello-World's main branch is master, so rename it in the bare repository with git branch -m master main. Skip this step when the source main branch is already main.

  • Push every branch and tag

--all pushes every branch. --tags pushes every tag. The example uses the SSH URL. An HTTPS URL works too. In the password field, paste an AngusGit access token. Keep the token in your own password manager.

git clone --bare https://github.com/octocat/Hello-World.git hello-world-history.git
cd hello-world-history.git
git branch -m master main
git push ssh://git@git.anguskit.com:2222/xlliu/hello-world-history.git --all
git push ssh://git@git.anguskit.com:2222/xlliu/hello-world-history.git --tags
Enter fullscreen mode Exit fullscreen mode

After the push, open the Branches tab. You should see every branch from the source, and the commit history should match the source. Prepare the SSH public key and the access token as at the start of this article.

6. Import many repositories at once

When there are many repositories, use Batch Import at the top right of Repositories. The page title is Batch Import Repositories. The tabs are Manual Input, To Import, and Imported.

On Manual Input, put one URL per line in Repository URLs, choose Owner, then click Add to Import List. The limit is 100 at a time. Batch import differs from a single import in three ways:

  • The repository name is the last part of the URL. https://github.com/octocat/Hello-World.git becomes Hello-World. You cannot rename each row in the list.
  • There is no Make this repository private switch. Every batch-imported repository is public. To make one private, open Settings → Access on that repository, set Visibility to private, and click Save visibility settings. Or use the single import in section 3. hello-world-import is the private result of that single import.
  • The import runs in a background queue, so you can leave the page after you submit. Progress is on the To Import tab. Each item shows Pending, then Processing, and ends as Success or Failed. Successful items appear under Imported. A failed item is not retried automatically. Expand the task to read the reason, fix the URL, and add it again.

Apart from those three points, batch import follows the same rules as a single import: it brings only the files on the default branch, and the source must be readable without signing in. Leave the existing anguskit/AngusRepo out of the list.

7. When the import fails

What you see Cause What to do
Please enter a valid repository URL under the field, and Begin import cannot be clicked The address does not start with https://, http://, or git@, or the path is missing Copy the HTTPS clone URL again from the source repository page
Source repository URL "…" is invalid or inaccessible The URL is wrong, the source is private, or the AngusGit server cannot reach the source Open the source page in a browser without signing in and confirm it is public. Then run git ls-remote <source-url> on the AngusGit server. For a private source, push as in section 5
Repository "xlliu/hello-world-import" already exists That owner already has a repository with this name, for example because it was imported once already Choose another Repository name. anguskit/AngusRepo already exists too. Do not use it as the import target
Failed to clone repository: … The fetch failed, for example because the network dropped Read the reason after the colon. For a network problem, try once more. If a large repository keeps dropping, use section 5
One batch item shows Failed Same causes as a single import Expand the task, read that item's error, fix it, and add it to the list again

Common questions

After the import, do new commits on the source show up here?

No. Import fetches the code once, at the moment you click Begin import. Later commits on the source are not copied automatically. To pick up those commits, import again under a new name, or use the push steps in section 5 and push the source, including the new commits, into a new empty repository.

Why is there only one commit after the import?

Import takes the files that were on the source default branch, creates a new repository on AngusGit from those files, and makes one commit. The old history, the other branches, and the tags stay behind. For Hello-World, the only commit is Initial commit from https://github.com/octocat/Hello-World.git. To keep the history, use section 5.

Does the same import work for GitLab and Gitee?

Yes. Put the HTTPS clone URL from the GitLab or Gitee project page into Repository URL. The steps and the rules are the same. The form hint names GitHub, GitLab, Gitee, and SourceForge. A platform such as GitBucket also works when you can reach it with a Git URL.

Can issues and pull requests move over too?

No. Import and push both move only what is inside the Git repository. Issues and pull requests are not in there. Merge or close in-progress pull requests on the source before you move. Recreate open issues under Issues on AngusGit.

What if the source uses Git LFS?

Git LFS (Git Large File Storage) is an add-on that stores large files outside normal Git history. AngusGit does not support it. After an import or a push, each LFS file is only a pointer file (a short text file that records where the content lived). The original content does not come over. Commit those files as normal files, or store them in an artifact repository.

Summary

Import repository fits when you only need the current version of the code. The source must be public. The result is the files from the default branch and one Initial commit from …. History, other branches, and tags stay behind, and so do issues, pull requests, and CI. Hello-World became the private repository xlliu/hello-world-import, with one README on main. When the source is private, or you need every commit, every branch, and every tag, push instead: create an empty repository, then git clone --bare plus git push --all and --tags. The push target must be that new empty repository. Leave the already imported repository alone.

Conclusion: Import repository turns the files that were on a public source's default branch into one Initial commit from <source URL> (xlliu/hello-world-import put the README from master onto main). To keep the full history, every branch, and every tag, create an empty repository and push with git clone --bare plus git push --all and --tags.

Further reading

Top comments (0)