microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.3k stars 29.31k forks source link

syncing to empty github repository results in error #181945

Open SimonSiefke opened 1 year ago

SimonSiefke commented 1 year ago

Does this issue occur when all extensions are disabled?: Yes/No

Steps to Reproduce:

  1. Create an empty github repository
  2. Open the repository in vscode
  3. Create a file
  4. Commit and push the file using vscode
  5. An error is shown: git: fatal: couldn't find remote ref main

Using the terminal and running git push works as expected

Screencast of the issue: https://github-production-user-asset-6210df.s3.amazonaws.com/23744935/237189688-5afc569f-2966-4061-9b6e-0018d7501dfa.mp4

vscodenpa commented 1 year ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.78.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

lszomoru commented 1 year ago

@SimonSiefke, the issue with the disabled action following the commit has been fixed in the latest Stable/Insiders release. I will go ahead and optimistically close this issue but if you are still able to reproduce the problem please feel free to reopen it. Thanks!

SimonSiefke commented 1 year ago

I just checked and the problem still reproduces in 1.79-0 insiders. I think this is unrelated to the disabled action following the commit issue.

lszomoru commented 1 year ago

@SimonSiefke, so we are scoping the issue to the fact that you cannot push to a newly created GitHub repository. I have rewatched the recording that you have provided and couple of things that I would like you to try: 1) When you get the error when pressing the "Commit & Sync" button, can you please click on the "Show Command Output" button and share the contents as that will tell us more about the error that we are seeing. 2) Are you getting the same error message if you try to run git commit and git push from the integrated terminal?

SimonSiefke commented 1 year ago
  1. The command output is
> git pull origin main
fatal: couldn't find remote ref main

It seems the issue isn't with push, but with git pull since the remote main branch doesn't exist. I further narrowed down the issue to the following vscode git settings:

{
  "git.postCommitCommand": "sync",
  "git.confirmSync": false,
}

What would think about only running git pull only if the remote branch exists?

lszomoru commented 1 year ago

Yes, this is an edge case that we would have to handle. For the time being, when you run into this error you can run the "Git: Push" command which will create the remote branch. After that you should be able to successfully "Commit & Sync" without experiencing any errors.

PhilWenz commented 4 months ago

I have the same error rn. And it is really frustrating to use the terminal ever so on. It would be really cool if you can do this in VS Code just to safe some time and don't tap out every time just to create the branch..

heyitsritesh commented 4 months ago

Having the same issue from the last couple of days.

Screenshot 2024-06-27 at 4 16 06 PM
lorithai commented 1 month ago

Hi I may have a similar problem and found a workaround.

Problem I created an empty repository on github under a Organization. I cloned this repository in vscode using Source control -> clone repository and selecting the newly created one when it pops up in the upper field. When i try and sync or push changes to the repository i get a message that Git can't find the remote ref main.

Solution In github, create a file in the newly created repository (any text file will do) Clone the repository as before in vscode You can now sync and push changes to the repository.

Cause It seems like when you create a completely empty repository in github, the main branch isn't created. I am guessing vscode or git assumes that the main branch must be there.