VS Code中GitLens推送远程分支失效问题求助
问题描述
近几日尝试通过VS Code的GitLens扩展将分支推送至私有GitHub Enterprise仓库时持续失败,报错信息如下:
[2022-12-02 21:00:41.637] Failed to execute git { "exitCode": 128, "gitErrorCode": "RemoteConnectionError", "gitCommand": "push", "stdout": "", "stderr": "fatal: 'my-branch' does not appear to be a git repository\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n" }
已尝试操作:
- 重装GitLens扩展
- 在VS Code用户/工作区设置中配置私有GitHub Enterprise Server的URI,将
github-enterprise.uri设置为"my.corporate.github.com/Organization"(已替换为真实地址)
环境信息:
- VS Code版本:1.73.1(Universal,Mac系统)
- GitLens版本:v13.1.1
补充:部分Git命令输出(已编辑敏感信息)
$ git status On branch my-branch Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: api/someFile.sh modified: docker/docker-compose.yml modified: docker/superfluous-edit.yml Untracked files: (use "git add <file>..." to include in what will be committed) docker/all-containers.sh no changes added to commit (use "git add" and/or "git commit -a")
$ git branch -avv | cat add-test-data 23411432 [origin/add-test-data] Refine name and add test data arm-docker-changes a7c88c7a [origin/arm-docker-changes: behind 2] Remove stray fwd'ing of port master b0b66b0b [origin/master: behind 3] Merge pull request #1653 from another_branch * my-branch df8a65e7 Merge to local ... more branch/commit descriptions, nothing else ...
解决步骤
从报错和Git输出来看,核心问题是my-branch分支未关联远程仓库,导致GitLens推送时找不到对应远程地址,按以下步骤处理:
检查并添加远程仓库关联
在终端执行git remote -v,确认本地仓库已关联正确的私有GitHub Enterprise地址,正常输出应类似:origin git@my.corporate.github.com:Organization/repo-name.git (fetch) origin git@my.corporate.github.com:Organization/repo-name.git (push)若无输出,说明未关联远程仓库,执行命令添加:
git remote add origin git@my.corporate.github.com:Organization/repo-name.git(替换为你的真实仓库地址)
关联本地分支到远程分支
从git branch -avv输出可见,my-branch后无[origin/my-branch]标记,说明未关联远程分支,执行命令完成关联并推送:git push --set-upstream origin my-branch验证GitLens识别状态
完成上述操作后重启VS Code,打开GitLens查看分支列表,确认my-branch已显示远程分支关联,再尝试推送即可正常执行。排查访问权限问题
若仍报错,检查私有仓库访问权限:- 确认SSH密钥已添加至GitHub Enterprise账号
- 在终端执行
git fetch origin,验证能否正常拉取远程内容
内容的提问来源于stack exchange,提问作者AckThpfft
相关产品推荐
相关产品推荐

