Changing a Git Repository Location

Switching from Github to or Bitbucket? Git is actually pretty flexible when it comes to changing around the location of the remote repository if you are switching hosts.

Here are the steps:

  1. Make sure you’ve pulled all the latest commits to a local copy of your repository
  2. Create a new, empty repository in the new location and grab the url / link to this new location
  3. Open the “config” file in the hidden “.git” folder insider your directory. You’ll have to make sure hidden files are showing on a Mac.
  4. Change the remote URL you see in this file to the new remote location url of your repository that you grabbed in step 2.
  5. Open your local repository path in terminal (just type “cd” and then drag the folder you’re working with into the terminal window as a shortcut).
  6. Now type in the following command “git push -u origin master”

That’s it! All your files and commit / change history should now be safely stored in the new location. You can now delete your previous repository.

Note: You can also store multiple remote repositories in your config file and call them different names, other than “origin” for more complicated workflows.