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
Change remote git URI to
git@github.com
rather thanhttps://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
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...
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>
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.)
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.