TechTip: Moving a Project Between Git Repositories

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:

  1. 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)
  2. 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)
  3. 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)
  4. Sync the project to the new remote repository (if any issues occur the old url is still available)
  5. Delete the old url (only after confirming that everything works fine with the new url)
    git remote rm oldrepo

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top