You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

向GitLab推送代码时被要求输入GitHub凭证问题求助

Git推送混淆GitLab与GitHub的问题解决

问题描述

我在GitLab GUI上创建了一个项目,现在想往这个已有项目推送文件。执行git remote add origin https://git.doit.wisc.edu/my_user_name/my-website.git时,收到错误提示:error: remote origin already exists.,于是我跳过这步,执行git branch -M main,输入钥匙串密码后无异常。但执行git push -uf origin main时,终端提示输入Username for 'https://github.com':,输入用户名后收到错误:

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.

实际我要推送到GitLab而非GitHub,请问操作中遗漏了什么?

原因

你的本地仓库里origin这个远程仓库地址早就被设置成GitHub的了,跳过添加远程的步骤后,Git依然会使用旧的GitHub地址进行推送,所以才出现了混淆。

解决方法

方法一:直接更新现有远程地址

  1. 先确认当前origin的地址,执行:
    git remote -v
    你会看到输出里origin对应的是GitHub的地址。

  2. 将origin的地址替换为你的GitLab项目地址:
    git remote set-url origin https://git.doit.wisc.edu/my_user_name/my-website.git

  3. 重新执行推送命令:
    git push -uf origin main
    这时候就会指向你的GitLab仓库,按提示完成认证即可。

方法二:删除旧远程后重新添加

  1. 删除现有的GitHub远程地址:
    git remote remove origin

  2. 添加你的GitLab项目作为新的origin远程:
    git remote add origin https://git.doit.wisc.edu/my_user_name/my-website.git

  3. 执行推送命令:
    git push -uf origin main

内容的提问来源于stack exchange,提问作者DiamondJoe12

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 17:48:30