Importing from Git
Migrating an existing Git repository to XetHub is quick and easy.
Create and clone a new repository
Using the (+) dropdown on the top right of the XetHub UI, create a new repository and use the Access button to copy the Clone command, which will look something like this:
git xet clone xet@xethub.com:<user>/<repo>.git
If you already have a populated folder on your local machine with this repository name, run the command with a xet-
appended directory name at
the end so that you can distinguish it as your new Xet repository:
git xet clone xet@xethub.com:<user>/<repo>.git <repo>-xet
Otherwise just run the clone command as copied.
Navigate to the directory and make sure that you're on the main branch:
cd <repo-name>
git checkout main
Migrate an existing Git repository to XetHub
The following code assumes that you want to import the main branch from your remote repository. To import a different branch,
replace the main
in existing/main
with the name of that branch.
All these commands should be run in the root directory of your repository.
Setup
-
From your Xet repository's directory, add your existing Git repository as a remote named
existing
:git remote add existing <existing repository's Git URL>
-
Fetch all branches and commits from
existing
locally.git fetch existing
Import files while preserving Git history
Existing Git repositories can be migrated along with their history if any included binary files haven't been modified.
-
Check out a new temporary branch containing the contents of existing repository, then replay the temporary branch onto the main XetHub branch.
git branch temp_branch existing/main && git checkout temp_branch
git rebase main -m -s theirs -f --exec "git checkout main -- .gitattributes && git add --renormalize . && git commit --amend --no-edit"
git checkout main && git reset --hard temp_branch -
Now that the files and Git history have been migrated, remove the temporary branch:
git branch -D temp_branch
Occasionally, the commands above will fail if the migrated Git repository includes binary files that have been moved or changed. If the approach above fails due to errors, we recommend importing the repository without history. This can be done with the following command, which adds all files from an existing repository's main branch as a new commit:
git ls-tree -r -z --name-only existing/main | xargs -0 git checkout existing/main && git add . --renormalize && git commit -a -m "Imported files."
Completing the process
-
Verify that the new history of main makes sense and matches the history of your main branch.
git log
-
(Optional) Remove the existing remote.
git remote remove existing
-
(Optional) Reorganize directory structure, if needed, to support the co-location of code and assets.
-
Push the
main
branch to the XetHub remote.git push origin
The main branch of your existing Git repository code has now been successfully migrated into a Xet repository!