📜  git change origin url - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:15:16.507000             🧑  作者: Mango

Git Change Origin URL - Shell/Bash

As a programmer, it's common to work with Git repositories. One of the most common tasks is to update the origin URL of a repository. This can be done easily with Shell/Bash commands.

Steps to Change Origin URL

To change the origin URL of a Git repository, follow these steps:

  1. Open the terminal or command prompt where the repository is located.

  2. Type the following command:

    git remote set-url origin <new_url>
    

    Replace <new_url> with the new URL for the repository.

  3. Press Enter.

  4. Verify that the new URL has been set by typing:

    git remote -v
    

    This will display the old and new URLs.

Example Usage

Let's say you have a repository named my_project and the current origin URL is git@oldrepo.com:my_project.git. You want to change the origin URL to https://newrepo.com/my_project.git. Here's how you can do it:

cd my_project
git remote set-url origin https://newrepo.com/my_project.git
git remote -v

This will update the origin URL of the my_project repository to https://newrepo.com/my_project.git.

Conclusion

In this tutorial, we have learned how to change the origin URL of a Git repository using Shell/Bash commands. Updating the origin URL is a simple process and can be done in just a few steps.