Importing a Git repository using the command line
If GitHub Importer is not suitable for your purposes, such as if your existing code is hosted on a private network, then we recommend importing using the command line.
1.Create a new repository on GitHub.
Create a new repository on GitHub.
You’ll import your external Git repository to this new repository.
On the command line, make a “bare” clone of the repository using the external clone URL. This creates a full copy of the data, but without a working directory for editing files, and ensures a clean, fresh export of all the old data.
2.Makes a bare clone of the external repository in a local directory
$ git clone --bare https://old-host.com/old-user/repo.git
3.Pushes the mirror to the new repository on GitHub.com
Push the locally cloned repository to GitHub using the “mirror” option, which ensures that all references, such as branches and tags, are copied to the imported repository.
$ cd repo.git
$ git push --mirror https://github.com/gh-new-user/repo.git
Practice:
PS C:\Users\XXXXX\temp-del-march\junit-test
git clone --bare git@gitlab.com:chenxxxxxXXXX/junit5-test.git
Cloning into bare repository ‘junit5-test.git’…
remote: Enumerating objects: 42, done.
remote: Counting objects: 100% (42/42), done.
remote: Compressing objects: 100% (28/28), done.
remote: Total 42 (delta 4), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (42/42), 53.92 KiB | 4.90 MiB/s, done.
Resolving deltas: 100% (4/4), done.
PS C:\Users\XXXXX\temp-del-march\junit-test
ls
Directory: C:\Users\XXXXX\temp-del-march\junit-test
Mode LastWriteTime Length Name
it
PS C:\Users\XXXXX\temp-del-march\junit-test
cd junit5-test.git
PS C:\Users\XXXXX\temp-del-march\junit-test\junit5-test.git
git push --mirror https://github.com/sxxxxchenXXXX/junit-test.git
git: ‘credential-cache’ is not a git command. See ‘git --help’.
git credential-'cache store: -c: line 0: unexpected EOF while looking for matching '' git credential-'cache store: -c: line 1: syntax error: unexpected end of file git credential-'cache store: -c: line 0: unexpected EOF while looking for matching
‘’
git credential-‘cache store: -c: line 1: syntax error: unexpected end of file
git credential-‘cache store: -c: line 0: unexpected EOF while looking for matching `’’
git credential-'cache store: -c: line 1: syntax error: unexpected end of file
Enumerating objects: 42, done.
Counting objects: 100% (42/42), done.
Delta compression using up to 8 threads
Compressing objects: 100% (24/24), done.
Writing objects: 100% (42/42), 53.92 KiB | 13.48 MiB/s, done.
Total 42 (delta 4), reused 42 (delta 4), pack-reused 0
remote: Resolving deltas: 100% (4/4), done.
To https://github.com/sxxxxchenXXXX/junit-test.git
- [new branch] feature_chenxx03 -> feature_chenxx03
- [new branch] master -> master