How to change git hosting

Sometimes you need to change the code hosting platform, and you may encounter many problems in the process of migrating from github, gitlab or Bitbucket to other platforms. This article starts from the two requirements of whether to keep historical submission records, and introduces the git hosting platform-based Migration method.

1. Migration method that requires keeping all submission records

1. Clone a bare repository from an old hosted repository.

git clone –bare git://github.com/yourname/src_project.git

--bare: Clone a bare repository.

The name of the bare repository generally uses the original repository name plus the .git suffix. It does not contain the workspace, but is directly the content of the repository. The included files are shown in the figure below, which is similar to the content of the .git folder in the normal repository. .

2. Create a new project on a new Git server, such as Huawei Software Development Cloud Configuration Management Service.

New warehouse address:

[email protected]:f9c39cc7617a4caf9cb03d6bc8c3ac8a/dst_project.git

3. Push the local bare version to the Huawei Software Development Cloud Warehouse as an image.

git push –mirror[email protected]:f9c39cc7617a4caf9cb03d6bc8c3ac8a/dst_project.git

--mirror specifies that all files under refs/ are mirrored to push to the remote repository, instead of naming each ref to push one by one. Locally updated refs will be forcibly updated to the remote repository, and locally deleted refs will also be forcibly deleted from the remote repository.

Because the local and remote repositories are two different origins, if you do not select image push, the following error will occur:

Tip: Huawei Software Development Cloud enables branch protection for the master branch by default, so you need to remove the branch protection before pushing.

4. Delete the local bare version repository, the src_project.git folder.

5. Clone a copy of the code from the new hosting server to the local.

git clone[email protected]:f9c39cc7617a4caf9cb03d6bc8c3ac8a/dst_project.git

2. Migration method without keeping commit records

1. Download a set of code from the old hosting repository. Just code, no git version management related stuff.

2. Create a new project on the new Git server.

New warehouse address:

[email protected]:f9c39cc7617a4caf9cb03d6bc8c3ac8a/dst_project.git

3. git init #Initialize the warehouse under the local code root folder

4、git remote add [email protected]:f9c39cc7617a4caf9cb03d6bc8c3ac8a/dst_project.git

5. git pull origin master –rebase #Pull the existing content from the newly hosted repository

6、git add .

7、git commit

8. git push --set-upstream origin master #Associate the upstream hosting repository and push the old code

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326487465&siteId=291194637