Sometimes you want to change the repository to another URL (for example after you forked a repository and want to switch to your fork without any effort) or you want to change the protocol (HTTPS → SSH) to use your SSH keys. There are two methods available: via GIT commands and manual by modifying the configuration files. This article covers the latter case.
Excursus: GIT is saving all its information in files within the hidden
./.git sub folder in your cloned folder. The magic behind GIT is simply based on lists of hashes that are built together to create/modify your files. Each branch is in the end just a long list of hashes of single commits. The same applies to the configuration.
Open the file
./.git/config . You will see something similar to:
[core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true [remote "origin"] url = firstname.lastname@example.org:TechupBusiness/myrepo.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [branch "techup-improvements"] remote = origin merge = refs/heads/techup-improvements
If you have multiple remote repositories or more branches, you would see them listed here.
To change the URL you simply need to change the
url = git@… section and replace the value with your desired URL (new repository URL or HTTPS address). For example to switch to HTTPS and another repo:
url = https://github.com/TechupBusiness/other-repo.git
That’s it. After saving, all your
git command will use the new destination.
Good luck! :-)