如何更改远程 Git 存储库的 URI (URL)?
我在我的硬盘驱动器(本地)上克隆的 USB 密钥上有一个存储库(来源)。我将“origin”移至 NAS,并成功测试从这里克隆它。
我想知道是否可以在“本地”设置中更改“来源”的 URI,以便它现在将从 NAS 拉取,而不是从 USB 闪存盘拉取。
目前,我可以看到两种解决方案:
将所有内容推送到 USB 源,然后再次将其复制到 NAS(由于新提交到 NAS 源,意味着需要做大量工作);
向“本地”添加一个新的遥控器并删除旧的遥控器(我担心我会破坏我的历史记录)。
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 know if I can change the URI of "origin" in the settings of "local" so it will now pull from the NAS, and not from the USB key.
For now, I can see two solutions:
push everything to the USB origin, and copy it to the NAS again (implies a lot of work due to new commits to NAS origin);
add a new remote to "local" and delete the old one (I fear I'll break my history).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(30)
对我来说,接受的答案仅在提取的情况下有效,但在拉取的情况下无效。我做了以下操作以使其也适用于推送。
因此,要更新获取 URL:
要更新拉取 URL:
For me, the accepted answer worked only in the case of fetch but not pull. I did the following to make it work for push as well.
So to update the fetch URL:
To update the pull URL:
在 Git Bash 中,输入命令:
git remote set-url origin https://NewRepoLink.git
输入凭据
完成
In the Git Bash, enter the command:
git remote set-url origin https://NewRepoLink.git
Enter the Credentials
Done
您有很多方法可以做到这一点:
控制台
只要确保您已在存储库所在的位置打开它即可。
Config
它放置在 .git/config (与存储库相同的文件夹)
TortoiseGit
然后只需编辑 URL 。
SourceTree
单击工具栏上的“设置”按钮,打开“存储库设置”窗口。
单击
单击“添加”将远程存储库路径添加到存储库。将打开“远程详细信息”窗口。
输入远程路径的名称。
输入远程存储库的 URL/路径
输入远程存储库的托管服务的用户名。
单击“确定”添加远程路径。
返回“存储库设置”窗口,单击“确定”。新的远程路径现在应该添加到存储库中。
如果您需要编辑已添加的远程路径,只需单击“编辑”按钮即可。您应该被定向到“远程详细信息”窗口,您可以在其中编辑远程路径的详细信息(URL/路径/主机类型)。
要删除远程存储库路径,请单击“删除”按钮
参考。 支持
You have a lot of ways to do that:
Console
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)
TortoiseGit
Then just edit URL.
SourceTree
Click on the "Settings" button on the toolbar to open the Repository Settings window.
Click "Add" to add a remote repository path to the repository. A "Remote details" window will open.
Enter a name for the remote path.
Enter the URL/Path for the remote repository
Enter the username for the hosting service for the remote repository.
Click 'OK' to add the remote path.
Back on the Repository Settings window, click 'OK'. The new remote path should be added on the repository now.
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.
To remove a remote repository path, click the 'Remove' button
ref. Support
要更改远程上游:
git remote set-url origin
要添加更多上游:
git Remote add newplace
这样你就可以选择工作地点
git Push origin
或git Push newplace
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>
orgit push newplace <branch>
转到要更改的文件夹/存储库并执行以下命令:
以下命令将更改存储库的 git fetch url。
以下命令将更改存储库的 git Push url。
以下命令检查上述更改是否反映
Go to the folder/repo where you want to change and execute the below commands:
The below command will change the git fetch url of the repo.
The below command will change the git push url of the repo.
The below command to check whether the above changes reflected or not
删除远程
使用 git remote rm 命令从存储库中删除远程 URL。
Removing a remote
Use the git remote rm command to remove a remote URL from your repository.
另一种方法是重命名“旧”原点(在下面的示例中,我将其简单命名为
old-origin
)并添加一个新原点。如果您仍然希望能够时不时地推送到旧的原点,这可能是您想要的方法:并且如果您需要将本地状态推送到新的原点:
An alternative approach is to rename the 'old' origin (in the example below I name it simply
old-origin
) and adding a new one. This might be the desired approach if you still want to be able to push to the old origin every now and then:And in case you need to push your local state to the new origin:
您可以通过编辑配置文件来更改 url。
转到您的项目根目录:
然后编辑 url 字段并设置新的 url。
保存更改。您可以使用该命令验证更改。
You can change the url by editing the config file.
Go to your project root:
Then edit the url field and set your new url.
Save the changes. You can verify the changes by using the command.
如果您使用 TortoiseGit,请按照以下步骤操作:
TortoiseGit ->设置
Git ->远程
origin
URL
文本框值更改为新远程存储库所在的位置您的分支和所有本地提交都将保持不变您可以像以前一样继续工作。
If you're using TortoiseGit then follow the below steps:
TortoiseGit -> Settings
Git -> Remote
origin
URL
text box value to where ever your new remote repository isYour branch and all your local commits will remain intact and you can keep working as you were before.
检查您的权限,
在我的情况下,我需要检查我的用户名,
我有两个或三个具有单独凭据的存储库。
问题是我的权限我有两个私人 git 服务器和存储库,
第二个帐户是新存储库的管理员,第一个帐户是我的默认用户帐户,我应该向第一个帐户授予权限
check your privilege
in my case i need to check my username
i have two or three repository with seperate credentials.
problem is my permission i have two private git server and repositories
this second account is admin of that new repo and first one is my default user account and i should grant permission to first
这个答案与我在其他地方找不到答案的问题有关:为 Gitlab 中的一个项目执行此操作,该项目有一个子组。这确实通过 SSH 起作用:
与所有具有“用户名”而不是“组”的答案相比,这些答案都没有通过 SSH 对我起作用。或者,通过 https 实现的方法:
请注意“.com:group”和“.com/group”两者之间的区别
如果这不能立即使用,我在成功使用 SSH 之前使用了 HTTPS 方法一,可能是一个因素,但我不能在没有它的情况下尝试复制它。
This answer pertains to a question I wasn't able to find an answer for elsewhere: doing this for a project in Gitlab, which has a subgroup. This did work via SSH:
In contrast to all the answers which have "username" instead of "group", none of those worked for me via SSH. Alternatively, what worked through https:
Do note the difference in the two with ".com:group" and ".com/group"
If this doesn't work right out of the box, I used the HTTPS method before successfully using the SSH one, might be a factor but I can't be arsed to try and replicate it without it.
(仅限 Windows PS)在所有本地存储库中递归更改服务器/协议
(Only Windows PS) To change a server/protocol recursively in all local repos
您可以
查看
git help remote
。您还可以编辑.git/config
并更改其中的 URL。除非您做了一些非常愚蠢的事情,否则您不会面临丢失历史记录的危险(如果您担心,只需复制您的存储库,因为您的存储库就是您的历史记录。)
You can
See
git help remote
. You also 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.)
更改远程 URL
Changing a remote's URL
更改 Git 源服务器的主机< /a>
来自: http:// /pseudofish.com/blog/2010/06/28/change-host-for-a-git-origin-server/
希望这不是您需要做的事情。我用来协作处理几个 git 项目的服务器的域名已过期。这意味着找到一种迁移本地存储库以恢复同步的方法。
更新:感谢 @mawolf 指出最近的 git 版本(2010 年 2 月后)有一个简单的方法:
有关详细信息,请参阅手册页。
如果您使用的是旧版本,请尝试以下操作:
需要注意的是,这只适用于同一服务器,只是名称不同。
假设新主机名是
newhost.com
,旧主机名是oldhost.com
,则更改非常简单。编辑工作目录中的 .git/config 文件。您应该看到类似以下内容:
将
oldhost.com
更改为newhost.com
,保存文件即可完成。从我有限的测试(
git pull origin; git push origin;gitx
)来看,一切似乎都按顺序进行。是的,我知道搞乱 git 内部结构是不好的。Change Host for a Git Origin Server
from: http://pseudofish.com/blog/2010/06/28/change-host-for-a-git-origin-server/
Hopefully this isn’t something you need to do. The server that I’ve been using to collaborate on a few git projects with had the domain name expire. This meant finding a way of migrating the local repositories to get back in sync.
Update: Thanks to @mawolf for pointing out there is an easy way with recent git versions (post Feb, 2010):
See the man page for details.
If you’re on an older version, then try this:
As a caveat, this works only as it is the same server, just with different names.
Assuming that the new hostname is
newhost.com
, and the old one wasoldhost.com
, the change is quite simple.Edit the
.git/config
file in your working directory. You should see something like:Change
oldhost.com
tonewhost.com
, save the file and you’re done.From my limited testing (
git pull origin; git push origin; gitx
) everything seems in order. And yes, I know it is bad form to mess with git internals.这非常容易和简单;只需按照这些说明操作即可。
This is very easy and simple; just follow these instructions.
切换远程 URL
打开终端。
第一步:- 将当前工作目录更改为您的本地项目。
第二步:- 列出您现有的遥控器,以便获取您要更改的遥控器的名称。
git remote -v
使用 git remote set-url 命令将远程 URL 从 HTTPS 更改为 SSH。
第三步:-
git remote set-url origin [ email protected]:USERNAME/REPOSITORY.git
第四步:- 现在验证远程 URL 是否已更改。
git远程-v
验证新的远程 URL
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
Change your remote's URL from HTTPS to SSH with the git remote set-url command.
3rd Step:-
git remote set-url origin [email protected]:USERNAME/REPOSITORY.git
4th Step:- Now Verify that the remote URL has changed.
git remote -v
Verify new remote URL
(或者,打开
.git/config
,查找[remote "origin"]
,然后编辑url =
行。您可以检查它通过检查遥控器来工作:
下次推送时,您必须指定新的上游分支,例如:
另请参阅:GitHub:更改远程 URL
(alternatively, open
.git/config
, look for[remote "origin"]
, and edit theurl =
line.You can check it worked by examining the remotes:
Next time you push, you'll have to specify the new upstream branch, e.g.:
See also: GitHub: Changing a remote's URL
如此处所示,
As seen here,
它会工作得很好,你可以尝试这个
对于 SSH:
命令:
git remote set-url origin
示例:
git remote set-url origin [电子邮件受保护]:username/rep_name.git
对于 HTTPS:
命令:
git remote set-url origin
示例:
git remote set-url origin https://github.com/username/REPOSITORY.git
It will work fine, you can try this
For SSH:
command:
git remote set-url origin <ssh_url>
example:
git remote set-url origin [email protected]:username/rep_name.git
For HTTPS:
command:
git remote set-url origin <https_url>
example:
git remote set-url origin https://github.com/username/REPOSITORY.git
git Remote rm origin
git Remote add origin(从 Bit Bucket 中的项目存储库复制 HTTP URL)
完毕
git remote rm origin
git remote add origin (Copy HTTP URL from your project repository in bit bucket)
done
首先,您需要输入此命令来查看现有的遥控器
git remote -v
然后,您需要输入此命令来更改“原始”遥控器的 URL strong>
git remote set-url origin <粘贴您的 GitHub URL>
First you need to type this command to view existing remotes
git remote -v
Then second you need to type this command to Change the 'origin' remote's URL
git remote set-url origin <paste your GitHub URL>
示例:
好处是您可以当您使用时
git推送
自动ssh-agent :将脚本文件
$HOME/. ssh/agent
让它使用 预计如下:Example:
The benefit is that you may do
git push
automatically when you use ssh-agent :Put a script file
$HOME/.ssh/agent
to let it runsssh-add
using expect as below:从您的存储库终端编写以下命令:
请参阅此 链接了解有关更改远程 URL 的更多详细信息。
Write the below command from your repo terminal:
Refer this link for more details about changing the url in the remote.
检查 git 远程连接:
现在,将本地存储库设置为远程 git:
现在要使其成为上游或推送,请使用以下代码:
git push --set-upstream origin master -f
To check git remote connection:
Now, set the local repository to remote git:
Now to make it upstream or push use following code:
git push --set-upstream origin master -f
如果您想在原始网址中设置用户名和密码,您可以按照以下步骤操作。
将密码导出到变量中可以避免特殊字符的问题。
步骤:
If you would like to set the username and password as well in the origin url, you can follow the below steps.
Exporting the password in a variable would avoid issues with special characters.
Steps:
如果您克隆了本地将自动包含
克隆的远程 URL。
可以使用 git remote -v 来检查它
如果您想对其进行更改,
请使用
来源 - 您的分支
,如果您想覆盖, 现有的分支您仍然可以使用它..它将覆盖您现有的...它会
为您做...
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,
here,
origin - your branch
if you want to overwrite existing branch you can still use it.. it will override your existing ... it will do,
for you...
故障排除:
您在尝试更换遥控器时可能会遇到这些错误。
No such remote '[name]'
此错误意味着您尝试更改的遥控器不存在:
git remote set-url soake https://github.com/octocat/Spoon-Knife
fatal: No such Remote 'sofake'
检查您是否正确键入了远程名称。
参考:https://help.github.com/articles/chang- a-remote-s-url/
Troubleshooting :
You may encounter these errors when trying to changing a remote.
No such remote '[name]'
This error means that the remote you tried to change doesn't exist:
git remote set-url sofake https://github.com/octocat/Spoon-Knife
fatal: No such remote 'sofake'
Check that you've correctly typed the remote name.
Reference : https://help.github.com/articles/changing-a-remote-s-url/
导航到本地存储库的项目根目录并检查现有遥控器:
如果您的存储库使用 SSH,您将看到类似以下内容:
如果您的存储库使用 HTTPS,您将看到这样的内容:
更改 URL 是通过 git remote set-url 完成的。根据
git remote -v
的输出,您可以通过以下方式更改 URL:如果是 SSH,您可以从
REPOSITORY 更改 URL。 git
到NEW_REPOSITORY.git
如下:如果是 HTTPS,您可以将 URL 从
REPOSITORY.git
更改为NEW_REPOSITORY.git
例如:注意:如果您更改了 GitHub 用户名,则可以按照与上述相同的流程来更新用户名中的更改与您的存储库关联。您只需更新
git remote set-url
命令中的USERNAME
。Navigate to the project root of the local repository and check for existing remotes:
If your repository is using SSH you will see something like:
And if your repository is using HTTPS you will see something like:
Changing the URL is done with
git remote set-url
. Depending on the output ofgit remote -v
, you can change the URL in the following manner:In case of SSH, you can change the URL from
REPOSITORY.git
toNEW_REPOSITORY.git
like:And in case of HTTPS, you can change the URL from
REPOSITORY.git
toNEW_REPOSITORY.git
like:NOTE: If you've changed your GitHub username, you can follow the same process as above to update the change in the username associated with your repository. You would only have to update the
USERNAME
in thegit remote set-url
command.我工作:
I worked: