LRBlog

Logical Reality Design: Web Design and Software Development

Changing the origin of your git repository

July 16, 2008

This is pretty basic and there’s plenty of documentation on the web, but this morning I found it difficult to locate with a google search. Maybe I just didn’t know the right terms. (searching “git repository change origin” seems obvious to me, but the results were useless.) Hopefully this post will help people find the documentation they are looking for if they are searching the same way I was.

Anyway, suppose you have a local git repository that you cloned from some remote repository at, say git://user@dev.foo.com/git/repos/path, and you’ve been happily pulling, pushing and rebaseing to and from that remote repository. But now you or your team leader have moved that remote repository to a new location, and you’d like to point your repository to the new URL without having to do a full checkout.

What you need to do is change your ‘origin’ setting. Unfortunately, there’s no trivially easy way to do this from the command line in current versions of git. Instead, you edit .git/config in your project root, which may look something like this:

...
[remote "origin"]
        url = git://user@dev.foo.com/git/repos/path
        fetch = +refs/heads/*:refs/remotes/origin/*
...

or if your ‘remote’ is actually local:

...
[remote "origin"]
        url = /path/to/repos/on/this/machine
        fetch = +refs/heads/*:refs/remotes/origin/*
...

All you need to do is edit that file with your favorite editor and change the url = setting to your new location. Assuming the new repository is correctly set up and you have your URL right, you’ll be happily pushing and pulling to and from your new remote location.

Add A Comment