You may already know what is Git remote origin URL. But if you don’t know, Git remote URL is the link to your repository in GitHub, Bitbucket, or somewhere else. No matter which Git hosting service you use, the URL ends with “.git“
In this post, I will show how you can change your Git remote origin URL. This will be fairly quick & simple instruction.
How to change Git remote origin URL?
Before you attempt to change your Git remote origin URL, it’s a good practice to check the current remote URL first. To check your current Git remote origin URL, navigate to your project in your command line (terminal) and type the following command:
git remote -v
This above command will display the existing Git remote origin URL (as you see in the screenshot below).
Now if you see it’s pointing to a different repository than you want, you can change it.
If you clone someone else’s repository in your machine (computer), this will automatically point to the old repository from where you cloned. Let’s see how you can change it.
To change your remote origin URL, type the following command:
git remote set-url origin new_repository_url
Don’t forget to replace the “new_repository_url” with your actual repository URL.
This is how you can change your remote origin URL. And this repository could be any service like GitHub, BitBucket, GitLab, etc. The system is the same for everyone. If you want to use Git with GitHub, see this post.
If you don’t know how to find your remote origin URL, go to your repository, copy the URL & just add the “.git” end of the URL (without any space). See the screenshot below as a reference.
For further reading about Git, you can check the following posts:
|How to install Git on Windows & Mac?|
This will help if you already have not installed Git on your machine. But if you already have Git installed on your machine, you can skip it.
|How to connect local Git to a remote server?|
This is slightly similar to the current post that you’re reading now. The main difference is it’s connecting a new project to a remote server for the first time (not changing the existing one).
|Why is Git useful for an individual developer?|
Some of you may think that Git is not required for those who work individually or alone. In the above post, I explained the top most benefits & reasons to use Git even if you’re an individual developer or freelancer.
|Git branch: create, checkout, merge, list, command, delete & push|
This post contains all sorts of mostly used commands for the Git branch.
Now you know how to change the Git remote origin URL in your command line.
But if this is the first time you’re setting a remote URL, the command is different than you saw above. For the first time setting the remote URL, use this command instead
git remote add origin your_url_goes_here
To make your hand dirty, see the most commonly used git commands.