1

For the past few days, I've been trying to push a branch to a private repo from VS Code with the GitLens extension, only to have it fail with the following cryptic message:

[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"
}

I tried a reinstall of the extension, and setting the the (private) GitHub Enterprise Server URI in both User and Workspace settings. I also set the value of the github-enterprise.uri setting to "my.corporate.github.com/Organization" (with real values of course).

For the record:

  • VS Code version: Version: 1.73.1 (Universal) (Mac)
  • GitLens version: v13.1.1

So it's clear that GitLens cannot find the name of the remote repo. How do I jog its memory?

For the record, some output from common commands (edited to avoid sensitive info):

$ 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 ...                                                           ```
AckThpfft
  • 51
  • 4
  • Does the output from `git remote -v` look ok? Do you get the same error if you run `git push origin my-branch`? – hlovdal Dec 02 '22 at 23:29
  • This works: git -C my_repo_dir push origin \`git rev-parse --abbrev-ref HEAD\` But the VS Code UI is tripping over the push. So the local repo is in good shape, it's VS Code / GitLens that's choking. – AckThpfft Dec 07 '22 at 14:49

2 Answers2

2

As I suspected, it was a GitLens issue. I resolved it by just upgrading to a pre-release version (v2022.12.904) of that extension.

Unfortunately, I don't have any more information as to what exactly went wrong. I did post an issue on GitLens' repo, however.

AckThpfft
  • 51
  • 4
  • "v2022.12.904": do you mean [Visual Studio](https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes)? (instead of [Visual Studio Code](https://code.visualstudio.com/updates/v1_74))? [VSCode GitLens](https://github.com/gitkraken/vscode-gitlens/releases) is only at 13.1.1. I will monitor [your issue](https://github.com/gitkraken/vscode-gitlens/issues/2379). – VonC Dec 09 '22 at 16:15
0

From a terminal within VSCode, reset the remote to the URL (HTTPS or SSH) of the remote repository:

cd /path/to/local/repository
git remote set-url https://server/you/yourRepository
# or
git remote set-url origin git@server:you/yourRepository

# test it:
git fetch

Check then the result of git branch -avv to check your my-branch is indeed listed.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Tried that, everything looks OK. But VS Code/GitLens is still giving me grief whenever I try to push changes to the remote from the UI. – AckThpfft Dec 07 '22 at 14:50
  • @AckThpfft Can you edit your question with the output of `git status` and `git branch -avv`, done from the root folder of your local repository? – VonC Dec 07 '22 at 14:54
  • Done. But again, I don't think git is the problem, I think it's the VS Code / GitLens UI. – AckThpfft Dec 08 '22 at 18:50
  • @AckThpfft Let's make it work in command line first. Try and push your branch with `git push -u origin my-branch`. *Then* you can switch back to an IDE/editor and see if the issue persists. – VonC Dec 08 '22 at 19:36
  • No problem.. in fact, it's what I've been doing. – AckThpfft Dec 08 '22 at 22:39
  • @AckThpfft Do you mean you still get `does not appear to be a git repository` after a `git push -u origin my-branch`? – VonC Dec 09 '22 at 06:29
  • That was the case. It was a GitLens issue; check out my answer below. The repo was AOK. Thanks for taking the time to work on this, btw. – AckThpfft Dec 09 '22 at 20:02
  • @AckThpfft Yes, I already left a comment below your answer. – VonC Dec 09 '22 at 20:30