How to change URL of Git remote origin
📋 Table Of Content
In this post, we will learn how to change URL of a remote Git repository.
Git is a decentralized version control system that lets us work on different projects in collaboration with other programmers.
So whatever changes we make to the project locally, Git allows us to push them to the remote repository too.
Now sometimes while working in Github or Bitbucket we might need to change the git origin remote to a new URL.
So how can we change the remote URL of our git repository?
To change the URL of our Git remote origin we have to use the git command
git remote set-url and specify the name and the URL of the new Git remote origin.
Let's see the process in a step-by-step process.
Change Remote Git Repository URL
Step 1: Go to the working directory of your local project.
Step 2: Find the remote git URL using
git remote -v, this will display the current Repository URL
origin https://github.com/USERNAME/Repository.git (fetch) origin https://github.com/USERNAME/Repository.git (push)
Step 3: Change the old URL with the new Git URL using this command:
git remote set-url origin https://github.com/USERNAME/GitRepo.git
To get the URL of your Git Repository go to your Github project repository and then click on “Code" button on the right corner. There you will find your repository URL.
Step 4: Once you have changed it, you can verify your new remote origin URL, by using the command:
git remote -v
You can also change the Git remote URL of your repo manually from the
.git/config file too. However, it is not a recommended way.
To change it manually, go to your
.gitfolder in your root directory and open the
You will see something like this:
[core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true [remote "origin"] url = https://github.com/USERNAME/repo-name.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master
Here, you can change the URL of your git remote origin and save the config file. Then verify the changed URL from your terminal using
git remote -v.
What is a remote origin in git?
Whenever we clone a repository to our local computer, it automatically creates a connection called origin pointing back to the cloned remote repository.
How to rename a local and remote Git branch
How to add empty folder/directory in Git