Andy Crouch - Code, Technology & Obfuscation ...

Changing A Git Repository's Origin Settings

Photo: Unsplash - Luke Chesser

This week I completely managed to screw up some git settings for a project. I learnt that you can simply update the origin when using a service such as Gitlab/Github/Bitbucket. This can be useful as well if you are transferring code or repository ownership.

Firstly you need to see what remotes you have configured with:

my-test-project $ git remote -v

This will output a list of the configured remotes such as;

my-test-project $ git remote -v
origin (fetch)
origin (push)

There are two remotes configured based on where to fetch from and where to push to.

If you are not using ssh your output will almost certainly be based on https:

my-test-project $ git remote -v
origin (fetch)
origin (push)

To update the remotes you first remove the existing entry:

my-test-project $ git remote rm "remote_name"

So if the example we are using it would be:

my-test-project $ git remote rm origin

You can then add the new remote details using:

my-test-project $ git remote add "remote_name" "remote_path"

In our example that might look like:

my-test-project $ git remote add origin

Hopefully this is a helpful but if you have question please contact me via twitter or email.