我在我的硬盘上(本地)克隆的USB键上有一个repo(起源)。我将“起源”转移到NAS,并成功测试了从这里克隆。

我想知道我是否可以在“本地”设置中更改“起源”的URI,所以它现在将从NAS中拖动,而不是从USB键。

到目前为止,我可以看到两个解决方案:

把一切推到USB起源,然后将其复制到NAS(这意味着由于NAS起源的新承诺而付出很多工作);添加一个新的远程到“本地”并删除旧的(我担心我会打破我的历史)。


当前回答

更改远程 git URI 到 git@github.com 而不是 https://github.com

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

例子:

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

优点是,当您使用 ssh 代理时,您可以自动进行 git push :

#!/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

插入一个脚本文件 $HOME/.ssh/agent 让它运行 ssh-add 使用预期如下:

#!/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

其他回答

git remote set-url origin git://new.location

(替代,打开.git/config,搜索 [远程“起源”),并编辑 url = 行。

你可以检查它工作,通过检查远程:

git remote -v
# origin  git://new.location (fetch)
# origin  git://new.location (push)

接下来的按钮,你将不得不指定新的上流分支,例如:

git push -u origin master

此分類上一篇: GitHub: 更改遠程 URL

进入文件夹/repo,您要更改并执行下面的命令:

下面的命令将改变 repo 的 git fetch URL。

git remote set-url origin <your new url>.git

下面的命令将改变 repo 的 git push URL。

git remote set-url --push origin <your new url>.git

下面的命令检查上面的变化是否反映

git remote -v

此分類上一篇: git remote set-url {name} {url}

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

更改远程 git URI 到 git@github.com 而不是 https://github.com

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

例子:

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

优点是,当您使用 ssh 代理时,您可以自动进行 git push :

#!/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

插入一个脚本文件 $HOME/.ssh/agent 让它运行 ssh-add 使用预期如下:

#!/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

转换远程URL

开放终端。

Ist 步骤: 将当前工作目录更改为本地项目。

第二步:列出您的现有远程,以获得您想要更改的远程的名称。

远程 -v

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

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

从 HTTPS 更改远程 URL 到 SSH 使用 git 远程设置 URL 命令。

第三步:- git 远程设置 URL 起源 git@github.com:USERNAME/REPOSITORY.git

步骤4:现在确保远程 URL 已改变。

git 远程 -v 查看新远程 URL

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