GitHub项目迁移到GitLab
1.克隆GitHub项目到本地
[root@gitclient ~]# mkdir gitrepos
[root@gitclient ~]# cd gitrepos
[root@gitclient gitrepos]# git init .
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /root/gitrepos/.git/
[root@gitclient gitrepos]# git clone https://github.com/xxx/easy-springmvc-maven.git
Cloning into 'easy-springmvc-maven'...
remote: Enumerating objects: 48, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 48 (delta 0), reused 2 (delta 0), pack-reused 45 (from 1)
Receiving objects: 100% (48/48), 9.16 KiB | 1.53 MiB/s, done.
Resolving deltas: 100% (9/9), done.
[root@gitclient gitrepos]# ls
easy-springmvc-maven
2. 在GitLab上创建同名新项目
3. 本地仓库重设远程仓库
[root@gitclient gitrepos]# cd easy-springmvc-maven/
[root@gitclient easy-springmvc-maven]# git remote -v
origin https://github.com/xxx/easy-springmvc-maven.git (fetch)
origin https://github.com/xxx/easy-springmvc-maven.git (push)
[root@gitclient easy-springmvc-maven]# git remote set-url origin git@192.168.100.31:plat-group/easy-springmvc-maven.git
[root@gitclient easy-springmvc-maven]# git remote -v
origin git@192.168.100.31:plat-group/easy-springmvc-maven.git (fetch)
origin git@192.168.100.31:plat-group/easy-springmvc-maven.git (push)
[root@gitclient easy-springmvc-maven]#
4. push代码到GitLab
[root@gitclient easy-springmvc-maven]# git push origin main:main
Enumerating objects: 48, done.
Counting objects: 100% (48/48), done.
Compressing objects: 100% (32/32), done.
Writing objects: 100% (48/48), 9.16 KiB | 9.16 MiB/s, done.
Total 48 (delta 9), reused 48 (delta 9), pack-reused 0
To 192.168.100.31:plat-group/easy-springmvc-maven.git* [new branch] main -> main
[root@gitclient easy-springmvc-maven]#
注:冒号前为本地分支,冒号后为远程分支,远程分支没有则创建。
5. 其他
5.1 报错解决
-
报错:
To 192.168.100.31:plat-group/easy-springmvc-maven.git
! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push[root@gitclient easy-springmvc-maven]# git push origin main:main Enumerating objects: 48, done. Counting objects: 100% (48/48), done. Compressing objects: 100% (32/32), done. Writing objects: 100% (48/48), 9.16 KiB | 9.16 MiB/s, done. Total 48 (delta 9), reused 48 (delta 9), pack-reused 0 remote: GitLab: remote: A default branch (e.g. main) does not yet exist for plat-group/easy-springmvc-maven remote: Ask a project Owner or Maintainer to create a default branch: remote: remote: http://192.168.100.31/plat-group/easy-springmvc-maven/-/project_members remote: To 192.168.100.31:plat-group/easy-springmvc-maven.git! [remote rejected] main -> main (pre-receive hook declined) error: failed to push some refs to '192.168.100.31:plat-group/easy-springmvc-maven.git'
-
原因:
权限不够
-
解决办法:
把GitLab用户设置为administrator,