TechTip: Moving a Project Between Git Repositories
I tend to write these so that I do not forget them, and possibly to help others who may be face similar challenges. The question is why would somebody want to do this, well usually its because of a change in Git hosting providers or probably change in project ownership.
The process is as follows:
- Check the configuration of the remote repository
local-box:change-url ssmusoke$ git remote -v origin https://github.com/ssmusoke/project-repo.git (fetch) origin https://github.com/ssmusoke/project-repo.git (push)
- Rename the url of the current remote repository from origin:
local-box:change-url ssmusoke$ git remote rename origin oldrepo local-box:change-url ssmusoke$ git remote -v oldrepo https://github.com/ssmusoke/project-repo.git (fetch) oldrepo https://github.com/ssmusoke/project-repo.git (push)
- Create a new origin pointing to the new remote repository
local-box:change-url ssmusoke$ git remote add origin https://github.com/ssmusoke/newproject-repo.git local-box:change-url ssmusoke$ git remote -v oldrepo https://github.com/ssmusoke/project-repo.git (fetch) oldrepo https://github.com/ssmusoke/project-repo.git (push) origin https://github.com/ssmusoke/newproject-repo.git (fetch) origin https://github.com/ssmusoke/newproject-repo.git (push)
- Sync the project to the new remote repository (if any issues occur the old url is still available)
- Delete the old url (only after confirming that everything works fine with the new url)
git remote rm oldrepo