How to Move a Git Repository and Update the Remote URL git remote set-url

git remote set-url origin https://bitbucket.org/onlinesolutionsgroup/ner_webapp.git

When working with Git, there might come a time when you need to move a repository to a new location. This could be due to changing the hosting provider, reorganizing your projects, or simply needing to update the repository's remote URL. Fortunately, Git makes this process straightforward. In this post, I'll guide you through the steps to move your repository and update the remote URL using the git remote set-url command.

Step 1: Move the Repository

Before you can update the remote URL, you need to move your repository to its new location. Depending on your setup, this might involve:

  • Creating a new repository on a different Git hosting service (e.g., GitHub, GitLab, Bitbucket).
  • Migrating the repository to a new organization or account on the same platform.
  • Cloning the repository to a new directory structure if you're reorganizing your local projects.

Once the repository has been moved or recreated at the new location, you'll need to update the URL in your local repository to point to this new remote.

Step 2: Update the Remote URL

In your local repository, Git keeps track of where it should push and pull changes from. This is done via the remote URL, typically named origin. When the location of your remote repository changes, you need to tell Git about the new URL.

To update the remote URL, use the git remote set-url command. Here's how:

  1. Open a Terminal: Navigate to the root directory of your local Git repository.

  2. Set the New URL: Run the following command, replacing <new-url> with the URL of your new remote repository:

    git remote set-url origin <new-url>

     

    For example, if your repository was moved to a new GitHub repository, your command might look like this: 

     

    git remote set-url origin https://github.com/username/new-repo.git
     

    Verify the Change: To confirm that the URL has been updated successfully, you can use the git remote -v command, which will display the current remotes and their URLs:

 

Comments