Create Gitee Repository from GitHub
I already have GitHub repository, now need to create the same one on Gitee. The Gitee supports importing from GitHub:
Push code to both repositories
Check the current remote repo:
$ git remote -v
origin git@github.com:LarryDpk/pkslow-samples.git (fetch)
origin git@github.com:LarryDpk/pkslow-samples.git (push)
Add Gitee URL to the remote config:
$ git remote set-url --add origin git@gitee.com:larrydpk/pkslow-samples.git
Now we have two URL for pushing code:
$ git remote -v
origin git@github.com:LarryDpk/pkslow-samples.git (fetch)
origin git@github.com:LarryDpk/pkslow-samples.git (push)
origin git@gitee.com:larrydpk/pkslow-samples.git (push)
Let’s try!
Update one file and commit:
$ git commit -m "add gitee url"
[master 4982dc5] add gitee url
1 file changed, 3 insertions(+)
Push code:
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 357 bytes | 357.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:LarryDpk/pkslow-samples.git
3b350aa..4982dc5 master -> master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 357 bytes | 357.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To gitee.com:larrydpk/pkslow-samples.git
3b350aa..4982dc5 master -> master
From the console, the code is successfully pushed to both repositories.
Config file
There another way to config the remote repository. Just put your config in file: .git/config
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = git@github.com:LarryDpk/pkslow-samples.git
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@gitee.com:larrydpk/pkslow-samples.git
[branch "master"]
remote = origin
merge = refs/heads/master
We can add multiple remote
:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = git@github.com:LarryDpk/pkslow-samples.git
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@gitee.com:larrydpk/pkslow-samples.git
[remote "github"]
url = git@github.com:LarryDpk/pkslow-samples.git
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "gitee"]
url = git@gitee.com:larrydpk/pkslow-samples.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
Now we can just push to one remote repository:
$ git remote -v
gitee git@gitee.com:larrydpk/pkslow-samples.git (fetch)
gitee git@gitee.com:larrydpk/pkslow-samples.git (push)
github git@github.com:LarryDpk/pkslow-samples.git (fetch)
github git@github.com:LarryDpk/pkslow-samples.git (push)
origin git@github.com:LarryDpk/pkslow-samples.git (fetch)
origin git@github.com:LarryDpk/pkslow-samples.git (push)
origin git@gitee.com:larrydpk/pkslow-samples.git (push)
$ git push github
Everything up-to-date
$ git push gitee
Everything up-to-date
Note: Make sure you add the SSH key on GitHub and Gitee.
References: