- Published on
Transfer or Migrate existing git repository to GitHub
- Authors
- Name
- Bal Singh
As we know that GitHub announced free private repositories/projects for everyone and also lower down the prices for paid accounts as well. Now organization can make private repositories for development without paying any fees. So many users and organizations are thinking to move or migrate existing git repository to GitHub.
Migrate project with git history and branches is the main concern. So In this topic we will cover this as well. Here we are going to explain some steps to migrate your existing git repository to GitHub with git/commit history. In the example, We will use GitLab to GitHub. Generally, it will work for any git repository migration.
Migrate repo which is not cloned.
If you have a repo which is not cloned at your system, then you can follow the following steps:
Change to the directory where you want to clone. Here I am using Site
$ cd ~/Sites/
Clone the repo from GitLab using the --mirror
option
$ git clone --mirror [email protected]:soscodes/xyz.git
Change into newly created directory
$ cd xyz.git
Push to GitHub using the --mirror
option. The --no-verify
option skips any hooks.
$ git push --no-verify --mirror [email protected]:soscodes/xyz.git
Change back to project root directory
$ cd ../
Delete mirrored repo
$ rm -rf xyz.git
If you have a project/repository, which is already cloned at your system then follow the following steps. Make sure you have updated it before the push.
Change to the exisitng git repo
$ cd ~/Sites/my-project
Add github as remote location
$ git remote add github [email protected]:soscodes/my-project.git
Push to GitHub
$ git push --mirror github
Set origin url to GitHub repo
$ git remote set-url origin [email protected]:soscodes/my-project.git