问题一
问题描述
执行 git push origin 时报错,如下:
解决办法
执行
git remote add code-na2 git@github.com:code-na2/mos-mss.git
即发现远程仓库有问题,所以重新关联到新的远程仓库。
解决过程
- 查看本地配置
git config -- list 查看当前项目下所有 git 相关配置
配置结果:
credential.helper=osxkeychain
user.name=赵娜
user.email=zhaona12@meituan.com
url.https://.insteadof=git://
url.git://.insteadof=https://
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://github.com/gitna2/mos-mss.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.feature-5721399.remote=origin
branch.feature-5721399.merge=refs/heads/master
remote.upstream.url=https://github.com/gitna2/mos-mss.git
remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*
即包含用户名、邮箱、所有关联的远程仓库 remote(这里是origin、upstream)、及对应仓库下分支。
从结果发现远程仓库配置url有问题,故可删除现有错误配置,重新设置远程仓库。
- 重新关联现有远程仓库相关设置或直接新建一个远程配置
先删除现有 origin 关联(直接新建远程配置时不用):
git remote remove origin
再添加新的远端仓库并设置别名,这里使用别名 code-na2:
git remote add code-na2 git@github.com:code-na2/mos-mss.git
- 查看本地仓库下 branch
git branch -r
发现没有关联分支,所以要拉取代码:
git fetch code-na2
这样,再执行:
git push origin feature-5721399
就成功了
涉及关键命令
git config -- list 查看当前项目下所有 git 相关配置
git remote remove origin 删除现有远端仓库关联
git remote add code-na2 git@github.com:code-na2/mos-mss.git 添加远端仓库关联
git fetch code-na2 从远端拉去分支
git branch -r 本地所有仓库下 branch