Repository: vscode
Issue: Git - publish branch behave confusingly after git shallow clone
Labels: feature-request,git

UPD:

I have found the cause is `--depth=1` and `--single-branch` after reading https://stackoverflow.com/questions/23708231/git-shallow-clone-clone-depth-misses-remote-branches 

When I use git shallow clone, remote branches won't be updated so VSCode would not recognize the new branch as published. So the result is that it will constantly ask the user to publish the branch.

Anyone who will run into this situation is mostly an accident, so I suggest VSCode at least give some feedback on this case, and not constantly display the publish branch button which would be confusing.

_Originally posted by @TieWay59 in https://github.com/microsoft/vscode/issues/180317#issuecomment-1521397548_

Steps to Reproduce:

1. `git clone --depth=1 <repo> ` and read into the folder.
2.  create a branch and publish it by VSCode, the command VSCode would use is `git push -u origin <newbranch>`
3.  you'll see the branch has been uploaded but the VSCode always displays `publish branch` no matter how many times you click it.


![a gif to demonstrate](https://user-images.githubusercontent.com/40034603/234228982-40f1f9cf-b3e4-4b10-9b44-8db22000a9a1.gif)

For anyone who has the same problem, there are two ways to work around it:

1. `git remote set-branches origin --add newbranch` add the new branch manually.
2. `git fetch --unshallow` turn off shallow clone and fetch everything from remote.

---

Original post:

I encountered a problem with VSCode’s git integration when I tried to use git sparse-checkout to clone a subset of a large repository. After creating and switching to a new branch in VSCode, I was unable to publish the branch to the remote repository. However, I could still push the branch using the command line. Even after pushing the branch successfully, VSCode still showed the branch as unpublished. This is a very serious issue that affects my workflow.

<!-- ⚠️⚠️ Do Not Delete This! bug_report_template ⚠️⚠️ -->
<!-- Please read our Rules of Conduct: https://opensource.microsoft.com/codeofconduct/ -->
<!-- 🕮 Read our guide about submitting issues: https://github.com/microsoft/vscode/wiki/Submitting-Bugs-and-Suggestions -->
<!-- 🔎 Search existing issues to avoid creating duplicates. -->
<!-- 🧪 Test using the latest Insiders build to see if your issue has already been fixed: https://code.visualstudio.com/insiders/ -->
<!-- 💡 Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. -->
<!-- 🔧 Launch with `code --disable-extensions` to check. -->
Does this issue occur when all extensions are disabled?: Yes

<!-- 🪓 If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. -->
<!-- 📣 Issues caused by an extension need to be reported directly to the extension publisher. The 'Help > Report Issue' dialog can assist with this. -->
- VS Code Version: Version: 1.77.3(user setup)
  - Commit: 704ed7od4fd1c6bd6342c436f1ede30d1cff4710
  - Date: 2023-04-12T09:16:02.548Z (1 wk ago)
- OS Version: Windows 10 21H2

Steps to Reproduce:

1. `git clone --depth=1 --filter=blob:none --sparse  https://github.com/TieWay59/gccrs.git`
3. `cd .\gccrs\`
5. `git sparse-checkout set gcc/rust`
6. open vscode and create & switch to a new branch, that branch won't be able to be published by vs code. 

![image](https://user-images.githubusercontent.com/40034603/233071574-0b846e43-6f7a-46d0-9ad7-e7d7917d2281.png)

The commit has been uploaded to the remote by terminal git push, but vs code can't recognize it no matter how I reload or reset it.