如何更改远程 Git 存储库的 URI (URL)?

发布于 2024-08-25 02:10:36 字数 302 浏览 7 评论 0原文

我在我的硬盘驱动器(本地)上克隆的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

孤芳又自赏 2024-09-01 02:10:37

对我来说,接受的答案仅在提取的情况下有效,但在拉取的情况下无效。我做了以下操作以使其也适用于推送。

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

因此,要更新获取 URL:

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

要更新拉取 URL:

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

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.

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

So to update the fetch URL:

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

To update the pull URL:

git remote set-url --push origin new.git.url/here
回忆凄美了谁 2024-09-01 02:10:37

在 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

远昼 2024-09-01 02:10:37

您有很多方法可以做到这一点:

控制台

git remote set-url origin [Here new url] 

只要确保您已在存储库所在的位置打开它即可。

Config

它放置在 .git/config (与存储库相同的文件夹)

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

TortoiseGit

第 1 步 - 打开设置

第 2 步 - 更改 url

然后只需编辑 URL 。

SourceTree

  1. 单击工具栏上的“设置”按钮,打开“存储库设置”窗口。

    单击

  2. 单击“添加”将远程存储库路径添加到存储库。将打开“远程详细信息”窗口。

  3. 输入远程路径的名称。

  4. 输入远程存储库的 URL/路径

  5. 输入远程存储库的托管服务的用户名。

  6. 单击“确定”添加远程路径。

  7. 返回“存储库设置”窗口,单击“确定”。新的远程路径现在应该添加到存储库中。

  8. 如果您需要编辑已添加的远程路径,只需单击“编辑”按钮即可。您应该被定向到“远程详细信息”窗口,您可以在其中编辑远程路径的详细信息(URL/路径/主机类型)。

  9. 要删除远程存储库路径,请单击“删除”按钮

在此处输入图像描述

在此处输入图像描述

参考。 支持

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

Step 1 - open settings

Step 2 - change url

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

enter image description here

enter image description here

ref. Support

弄潮 2024-09-01 02:10:37

更改远程上游:
git remote set-url origin


添加更多上游:
git Remote add newplace

这样你就可以选择工作地点
git Push origingit 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> or git push newplace <branch>

永言不败 2024-09-01 02:10:37

转到要更改的文件夹/存储库并执行以下命令:

以下命令将更改存储库的 git fetch url。

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

以下命令将更改存储库的 git Push url。

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

以下命令检查上述更改是否反映

git remote -v

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.

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

The below command will change the git push url of the repo.

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

The below command to check whether the above changes reflected or not

git remote -v
金兰素衣 2024-09-01 02:10:37

删除远程

使用 git remote rm 命令从存储库中删除远程 URL。

$ 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)

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)
◇流星雨 2024-09-01 02:10:37

另一种方法是重命名“旧”原点(在下面的示例中,我将其简单命名为 old-origin)并添加一个新原点。如果您仍然希望能够时不时地推送到旧的原点,这可能是您想要的方法:

git remote rename origin old-origin
git remote add origin [email protected]>:<username>/<projectname>.git

并且如果您需要将本地状态推送到新的原点:

git push -u origin --all
git push -u origin --tags

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:

git remote rename origin old-origin
git remote add origin [email protected]>:<username>/<projectname>.git

And in case you need to push your local state to the new origin:

git push -u origin --all
git push -u origin --tags
不忘初心 2024-09-01 02:10:37

您可以通过编辑配置文件来更改 url。
转到您的项目根目录:

nano .git/config

然后编辑 url 字段并设置新的 url。
保存更改。您可以使用该命令验证更改。

git remote -v 

You can change the url by editing the config file.
Go to your project root:

nano .git/config

Then edit the url field and set your new url.
Save the changes. You can verify the changes by using the command.

git remote -v 
哽咽笑 2024-09-01 02:10:37

如果您使用 TortoiseGit,请按照以下步骤操作:

  1. 转到本地结帐文件夹,然后右键单击转到 TortoiseGit ->设置
  2. 在左侧窗格中选择Git ->远程
  3. 在右侧窗格中选择origin
  4. 现在将URL 文本框值更改为新远程存储库所在的位置

您的分支和所有本地提交都将保持不变您可以像以前一样继续工作。

If you're using TortoiseGit then follow the below steps:

  1. Go to your local checkout folder and right click to go to TortoiseGit -> Settings
  2. In the left pane choose Git -> Remote
  3. In the right pane choose origin
  4. Now change the URL text box value to where ever your new remote repository is

Your branch and all your local commits will remain intact and you can keep working as you were before.

柏林苍穹下 2024-09-01 02:10:37

检查您的权限,

在我的情况下,我需要检查我的用户名,

我有两个或三个具有单独凭据的存储库。

问题是我的权限我有两个私人 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

花开柳相依 2024-09-01 02:10:37

这个答案与我在其他地方找不到答案的问题有关:为 Gitlab 中的一个项目执行此操作,该项目有一个子组。这确实通过 SSH 起作用:

git remote add origin [email protected]:group/subgroup/project.git

与所有具有“用户名”而不是“组”的答案相比,这些答案都没有通过 SSH 对我起作用。或者,通过 https 实现的方法:

git remote add origin https://[email protected]/group/subgroup/project.git

请注意“.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:

git remote add origin [email protected]:group/subgroup/project.git

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:

git remote add origin https://[email protected]/group/subgroup/project.git

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.

萝莉病 2024-09-01 02:10:37

(仅限 Windows PS)在所有本地存储库中递归更改服务器/协议

Get-ChildItem -Directory -Recurse -Depth [Number] -Hidden -name | %{$_.replace("\.git","")} | %{git -C $_ remote set-url origin $(git -C $_ remote get-url origin).replace("[OLD SERVER]", "[NEW SERVER]")}

(Only Windows PS) To change a server/protocol recursively in all local repos

Get-ChildItem -Directory -Recurse -Depth [Number] -Hidden -name | %{$_.replace("\.git","")} | %{git -C $_ remote set-url origin $(git -C $_ remote get-url origin).replace("[OLD SERVER]", "[NEW SERVER]")}
薄荷→糖丶微凉 2024-09-01 02:10:36

您可以

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

查看git help remote。您还可以编辑 .git/config 并更改其中的 URL。

除非您做了一些非常愚蠢的事情,否则您不会面临丢失历史记录的危险(如果您担心,只需复制您的存储库,因为您的存储库就是您的历史记录。)

You can

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

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.)

围归者 2024-09-01 02:10:36
git remote -v
# View existing remotes
# origin  https://github.com/user/repo.git (fetch)
# origin  https://github.com/user/repo.git (push)

git remote set-url origin https://github.com/user/repo2.git
# Change the 'origin' remote's URL

git remote -v
# Verify new remote URL
# origin  https://github.com/user/repo2.git (fetch)
# origin  https://github.com/user/repo2.git (push)

更改远程 URL

git remote -v
# View existing remotes
# origin  https://github.com/user/repo.git (fetch)
# origin  https://github.com/user/repo.git (push)

git remote set-url origin https://github.com/user/repo2.git
# Change the 'origin' remote's URL

git remote -v
# Verify new remote URL
# origin  https://github.com/user/repo2.git (fetch)
# origin  https://github.com/user/repo2.git (push)

Changing a remote's URL

焚却相思 2024-09-01 02:10:36

更改 Git 源服务器的主机< /a>

来自: http:// /pseudofish.com/blog/2010/06/28/change-host-for-a-git-origin-server/

希望这不是您需要做的事情。我用来协作处理几个 git 项目的服务器的域名已过期。这意味着找到一种迁移本地存储库以恢复同步的方法。

更新:感谢 @mawolf 指出最近的 git 版本(2010 年 2 月后)有一个简单的方法:

git remote set-url origin ssh://newhost.com/usr/local/gitroot/myproject.git

有关详细信息,请参阅手册页。

如果您使用的是旧版本,请尝试以下操作:

需要注意的是,这只适用于同一服务器,只是名称不同。

假设新主机名是 newhost.com,旧主机名是 oldhost.com,则更改非常简单。

编辑工作目录中的 .git/config 文件。您应该看到类似以下内容:

[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://oldhost.com/usr/local/gitroot/myproject.git

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):

git remote set-url origin ssh://newhost.com/usr/local/gitroot/myproject.git

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 was oldhost.com, the change is quite simple.

Edit the .git/config file in your working directory. You should see something like:

[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = ssh://oldhost.com/usr/local/gitroot/myproject.git

Change oldhost.com to newhost.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.

时光暖心i 2024-09-01 02:10:36

这非常容易和简单;只需按照这些说明操作即可。

  1. 要添加或更改远程源:
    git 远程 set-url origin githubrepurl
    
  2. 要查看本地存储库中当前拥有哪个远程 URL:
    git远程显示原点
    

This is very easy and simple; just follow these instructions.

  1. For adding or changing the remote origin:
    git remote set-url origin githubrepurl
    
  2. To see which remote URL you have currently in this local repository:
    git remote show origin
    
凌乱心跳 2024-09-01 02:10:36

切换远程 URL

打开终端。

第一步:- 将当前工作目录更改为您的本地项目。

第二步:- 列出您现有的遥控器,以便获取您要更改的遥控器的名称。

git remote -v

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

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

使用 git remote set-url 命令将远程 URL 从 HTTPS 更改为 SSH。

第三步:- git remote set-url origin [ email protected]:USERNAME/REPOSITORY.git

第四步:- 现在验证远程 URL 是否已更改。

git远程-v
验证新的远程 URL

origin  [email protected]:USERNAME/REPOSITORY.git (fetch)
origin  [email protected]:USERNAME/REPOSITORY.git (push)

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 [email protected]:USERNAME/REPOSITORY.git

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

git remote -v
Verify new remote URL

origin  [email protected]:USERNAME/REPOSITORY.git (fetch)
origin  [email protected]:USERNAME/REPOSITORY.git (push)
↙温凉少女 2024-09-01 02:10:36
git remote set-url origin git://new.location

(或者,打开.git/config,查找[remote "origin"],然后编辑url =行。

您可以检查它通过检查遥控器来工作:

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

下次推送时,您必须指定新的上游分支,例如:

git push -u origin master

另请参阅:GitHub:更改远程 URL

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

(alternatively, open .git/config, look for [remote "origin"], and edit the url = line.

You can check it worked by examining the remotes:

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

Next time you push, you'll have to specify the new upstream branch, e.g.:

git push -u origin master

See also: GitHub: Changing a remote's URL

謌踐踏愛綪 2024-09-01 02:10:36

此处所示,

$ git remote rm origin
$ git remote add origin [email protected]:aplikacjainfo/proj1.git
$ git config master.remote origin
$ git config master.merge refs/heads/master

As seen here,

$ git remote rm origin
$ git remote add origin [email protected]:aplikacjainfo/proj1.git
$ git config master.remote origin
$ git config master.merge refs/heads/master
番薯 2024-09-01 02:10:36

它会工作得很好,你可以尝试这个

对于 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

缘字诀 2024-09-01 02:10:36
  1. 使用 gitbash 上的命令删除 origin
    git Remote rm origin
  2. 现在使用 gitbash 添加新的 Origin
    git Remote add origin(从 Bit Bucket 中的项目存储库复制 HTTP URL)
    完毕
  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
烛影斜 2024-09-01 02:10:36

首先,您需要输入此命令来查看现有的遥控器

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>

伪心 2024-09-01 02:10:36

将远程 git URI 更改为 [电子邮件受保护]< /code> 而不是 https://github.com


git remote set-url origin [email protected]:<username>/<repo>.git

示例:

git remote set-url origin [email protected]:Chetabahana/my_repo_name.git

好处是您可以当您使用时git推送自动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

将脚本文件 $HOME/. ssh/agent 让它使用 预计如下:

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

Change remote git URI to [email protected] rather than https://github.com

git remote set-url origin [email protected]:<username>/<repo>.git

Example:

git remote set-url origin [email protected]: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
迷你仙 2024-09-01 02:10:36

从您的存储库终端编写以下命令:

git remote set-url origin [email protected]:<username>/<repo>.git

请参阅 链接了解有关更改远程 URL 的更多详细信息。

Write the below command from your repo terminal:

git remote set-url origin [email protected]:<username>/<repo>.git

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

弥繁 2024-09-01 02:10:36

检查 git 远程连接:

git remote -v

现在,将本地存储库设置为远程 git:

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

现在要使其成为上游或推送,请使用以下代码:

git push --set-upstream origin master -f

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

孤君无依 2024-09-01 02:10:36

如果您想在原始网址中设置用户名和密码,您可以按照以下步骤操作。

将密码导出到变量中可以避免特殊字符的问题。

步骤:

export gituser='<Username>:<password>@'
git remote set-url origin https://${gituser}<gitlab_repo_url> 
git push origin <Branch Name>

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:

export gituser='<Username>:<password>@'
git remote set-url origin https://${gituser}<gitlab_repo_url> 
git push origin <Branch Name>
宫墨修音 2024-09-01 02:10:36

如果您克隆了本地将自动包含

克隆的远程 URL。

可以使用 git remote -v 来检查它

如果您想对其进行更改,

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

请使用

来源 - 您的分支

,如果您想覆盖, 现有的分支您仍然可以使用它..它将覆盖您现有的...它会

git remote remove url
and 
git remote add origin url

为您做...

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...

行雁书 2024-09-01 02:10:36

输入图像描述这里

故障排除:

您在尝试更换遥控器时可能会遇到这些错误。
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/

enter image description here

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/

吝吻 2024-09-01 02:10:36

导航到本地存储库的项目根目录并检查现有遥控器:

git remote -v

如果您的存储库使用 SSH,您将看到类似以下内容:

> origin  [email protected]:USERNAME/REPOSITORY.git (fetch)
> origin  [email protected]:USERNAME/REPOSITORY.git (push)

如果您的存储库使用 HTTPS,您将看到这样的内容:

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

更改 URL 是通过 git remote set-url 完成的。根据 git remote -v 的输出,您可以通过以下方式更改 URL:

如果是 SSH,您可以从 REPOSITORY 更改 URL。 gitNEW_REPOSITORY.git 如下:

$ git remote set-url origin [email protected]:USERNAME/NEW_REPOSITORY.git

如果是 HTTPS,您可以将 URL 从 REPOSITORY.git 更改为 NEW_REPOSITORY.git 例如:

$ git remote set-url origin https://github.com/USERNAME/NEW_REPOSITORY.git

注意:如果您更改了 GitHub 用户名,则可以按照与上述相同的流程来更新用户名中的更改与您的存储库关联。您只需更新 git remote set-url 命令中的USERNAME

Navigate to the project root of the local repository and check for existing remotes:

git remote -v

If your repository is using SSH you will see something like:

> origin  [email protected]:USERNAME/REPOSITORY.git (fetch)
> origin  [email protected]:USERNAME/REPOSITORY.git (push)

And if your repository is using HTTPS you will see something like:

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

Changing the URL is done with git remote set-url. Depending on the output of git remote -v, you can change the URL in the following manner:

In case of SSH, you can change the URL from REPOSITORY.git to NEW_REPOSITORY.git like:

$ git remote set-url origin [email protected]:USERNAME/NEW_REPOSITORY.git

And in case of HTTPS, you can change the URL from REPOSITORY.git to NEW_REPOSITORY.git like:

$ git remote set-url origin https://github.com/USERNAME/NEW_REPOSITORY.git

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 the git remote set-url command.

你不是我要的菜∠ 2024-09-01 02:10:36

我工作:

git remote set-url origin <project>

I worked:

git remote set-url origin <project>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文