idea已配置的git仓库地址 更换新的Git仓库地址 教程

发布于:2024-05-10 ⋅ 阅读:(24) ⋅ 点赞:(0)

文章目录

概要

先在idea控制台走一下流程

先将本地的git仓库删除

1. 查看当前远程仓库地址:

在终端或命令行中,导航到你的项目目录,并运行以下命令查看当前的远程仓库地址:

git remote -v

2. 移除远程仓库地址:

如果你想要完全移除远程仓库的地址,可以运行以下命令:

git remote remove <remote_name>  

其中,<remote_name> 是你想要移除的远程仓库的名称。通常,远程仓库的默认名称是 origin

例如,如果要移除名为 origin 的远程仓库,可以运行:

git remote remove origin
  1. 3 验证移除结果:

  2. 可以再次运行 git remote -v 命令来验证远程仓库地址是否已经被移除。

3. 拉取远程仓库的更新:首先,执行git pull命令,将远程仓库的更新合并到你的本地仓库中。

git pull origin master

1. 解决报错问题

To https://gitee.com/xzali/xxxxx.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/xzali/xxxxx.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

要解决这个问题,你可以在执行 git pull 命令时,添加 --allow-unrelated-histories 参数,以允许合并不相关的历史。

git pull origin master --allow-unrelated-histories

这会将远程仓库的更新合并到你的本地仓库中,即使它们没有共同的历史。完成合并后,你应该能够正常地推送你的更改到远程仓库中。

git push origin master

运行成功的信息

From https://gitee.com/xzali/xxxx
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 README.en.md | 36 ++++++++++++++++++++++++++++++++++++
 README.md    | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100644 README.en.md
 create mode 100644 README.md

更改idea工具流程

技术细节

点击push提交到远程仓库地址

小结

解决最后一个问题,当前的本地分支是dev切换分支报错,并且导致提交不到远程仓库master

报错问题

这个错误提示表明在切换分支时,有未跟踪的工作树文件会被检出的分支覆盖。为了解决这个问题,你可以执行以下步骤之一:

  1. 提交或者移除未跟踪的文件:如果这些文件对你的项目没有影响,可以通过将它们提交到当前分支或者移除它们来解决冲突。

    • 如果你想保留这些文件,可以将它们添加到暂存区并提交:

git add README.en.md README.md
git commit -m "Committing untracked files before switching branches"

  • 如果这些文件对你的项目没有用处,可以将它们删除:

    git rm README.en.md README.md

    2. 暂时存储未跟踪的文件:如果你不想提交或者删除这些文件,可以使用 git stash 命令将它们暂时存储起来,然后再切换分支。

    git stash push -u

现在就可以切换到master分支了,如下操作步骤

切换到master

切换成功

点击push提交上去

2. 报错问题解决

提交到远程仓库,还是有报错信息,这个问题在上面已有讲解《1. 报错问题解决》标题请上滑查看解决报错   

执行1. 报错问题解决,2.再执行小结的命令

切换分支哪里需要再操作,现在分支就是在master分支提交到远程仓库报错问题解决

这个错误提示表明推送操作被拒绝,因为远程仓库的 master 分支比你本地的 master 分支超前。这通常发生在你试图推送到一个已经包含了你本地没有的提交的分支。


网站公告

今日签到

点亮在社区的每一天
去签到