Changing A Git Repository's Origin Settings
26 November 2019
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 -vThis will output a list of the configured remotes such as;
my-test-project $ git remote -v
origin git@gitservice.com:my-test-project.git (fetch)
origin git@gitservice.com:my-test-project.git (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 https://gitservice.com:my-test-project.git (fetch)
origin https://gitservice.com:my-test-project.git (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 originYou 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 https://mygitservice.com/user/projectdetails.gitHopefully this is a helpful but if you have question please contact me via twitter or email.
Welcome to my site and blog. You can find out about me and read my thoughts on code and technology, start-ups and building things.