How to change the URI (URL) for a remote Git repository?

前端 未结 25 2030
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 00:28

I have a repo (origin) on a USB key that I cloned on my hard drive (local). I moved \"origin\" to a NAS and successfully tested cloning it from here.

I would like to

相关标签:
25条回答
  • 2020-11-22 01:08

    You have a lot of ways to do that:

    Console

    git remote set-url origin [Here new url] 
    

    Just be sure that you've opened it in a place where a repository is.

    Config

    It is placed in .git/config (same folder as repository)

    [core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
    [remote "origin"]
        url = [Here new url]  <------------------------------------
    ...
    

    TortoiseGit

    Then just edit URL.

    SourceTree

    1. Click on the "Settings" button on the toolbar to open the Repository Settings window.

    2. Click "Add" to add a remote repository path to the repository. A "Remote details" window will open.

    3. Enter a name for the remote path.

    4. Enter the URL/Path for the remote repository

    5. Enter the username for the hosting service for the remote repository.

    6. Click 'OK' to add the remote path.

    7. Back on the Repository Settings window, click 'OK'. The new remote path should be added on the repository now.

    8. If you need to edit an already added remote path, just click the 'Edit' button. You should be directed to the "Remote details" window where you can edit the details (URL/Path/Host Type) of the remote path.

    9. To remove a remote repository path, click the 'Remove' button

    ref. Support

    0 讨论(0)
  • 2020-11-22 01:09

    I worked:

    git remote set-url origin <project>
    
    0 讨论(0)
  • 2020-11-22 01:10

    git remote set-url {name} {url}

    ex) git remote set-url origin https://github.com/myName/GitTest.git

    0 讨论(0)
  • 2020-11-22 01:11

    To check git remote connection:

    git remote -v
    

    Now, set the local repository to remote git:

    git remote set-url origin https://NewRepoLink.git
    

    Now to make it upstream or push use following code:

    git push --set-upstream origin master -f

    0 讨论(0)
  • 2020-11-22 01:12

    Switching remote URLs

    Open Terminal.

    Ist Step:- Change the current working directory to your local project.

    2nd Step:- List your existing remotes in order to get the name of the remote you want to change.

    git remote -v

    origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
    
    origin  https://github.com/USERNAME/REPOSITORY.git (push)
    

    Change your remote's URL from HTTPS to SSH with the git remote set-url command.

    3rd Step:- git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

    4th Step:- Now Verify that the remote URL has changed.

    git remote -v Verify new remote URL

    origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
    origin  git@github.com:USERNAME/REPOSITORY.git (push)
    
    0 讨论(0)
  • 2020-11-22 01:13

    Removing a remote

    Use the git remote rm command to remove a remote URL from your repository.

        $ git remote -v
        # View current remotes
        > origin  https://github.com/OWNER/REPOSITORY.git (fetch)
        > origin  https://github.com/OWNER/REPOSITORY.git (push)
        > destination  https://github.com/FORKER/REPOSITORY.git (fetch)
        > destination  https://github.com/FORKER/REPOSITORY.git (push)
    
        $ git remote rm destination
        # Remove remote
        $ git remote -v
        # Verify it's gone
        > origin  https://github.com/OWNER/REPOSITORY.git (fetch)
        > origin  https://github.com/OWNER/REPOSITORY.git (push)
    
    0 讨论(0)
提交回复
热议问题