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

前端 未结 25 2006
爱一瞬间的悲伤
爱一瞬间的悲伤 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:00
    1. remove origin using command on gitbash git remote rm origin
    2. And now add new Origin using gitbash git remote add origin (Copy HTTP URL from your project repository in bit bucket) done
    0 讨论(0)
  • Change remote git URI to git@github.com rather than https://github.com

    git remote set-url origin git@github.com:<username>/<repo>.git
    

    Example:

    git remote set-url origin git@github.com:Chetabahana/my_repo_name.git
    

    The benefit is that you may do git push automatically when you use ssh-agent :

    #!/bin/bash
    
    # Check ssh connection
    ssh-add -l &>/dev/null
    [[ "$?" == 2 ]] && eval `ssh-agent`
    ssh-add -l &>/dev/null
    [[ "$?" == 1 ]] && expect $HOME/.ssh/agent
    
    # Send git commands to push
    git add . && git commit -m "your commit" && git push -u origin master
    

    Put a script file $HOME/.ssh/agent to let it runs ssh-add using expect as below:

    #!/usr/bin/expect -f
    set HOME $env(HOME)
    spawn ssh-add $HOME/.ssh/id_rsa
    expect "Enter passphrase for $HOME/.ssh/id_rsa:"
    send "<my_passphrase>\n";
    expect "Identity added: $HOME/.ssh/id_rsa ($HOME/.ssh/id_rsa)"
    interact
    
    0 讨论(0)
  • 2020-11-22 01:03

    if you cloned your local will automatically consist,

    remote URL where it gets cloned.

    you can check it using git remote -v

    if you want to made change in it,

    git remote set-url origin https://github.io/my_repo.git
    

    here,

    origin - your branch

    if you want to overwrite existing branch you can still use it.. it will override your existing ... it will do,

    git remote remove url
    and 
    git remote add origin url
    

    for you...

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

    To change the remote upstream: git remote set-url origin <url>


    To add more upstreams: git remote add newplace <url>

    So you can choose where to work git push origin <branch> or git push newplace <branch>

    0 讨论(0)
  • You can

    git remote set-url origin new.git.url/here
    

    (see git help remote) or you can edit .git/config and change the URLs there. You're not in any danger of losing history unless you do something very silly (and if you're worried, just make a copy of your repo, since your repo is your history.)

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

    Write the below command from your repo terminal:

    git remote set-url origin git@github.com:<username>/<repo>.git
    

    Refer this link for more details about changing the url in the remote.

    0 讨论(0)
提交回复
热议问题