Show git branch in Visual Studio Code - visual-studio-code

I have a project folder structure like this : Code/Repo/<repo_folder_name>/..subfolders and in the <repo_folder_name> i have the hidden .git folder because i cloned from Sourcetree to this folder .
Eclipse does show the current branch , but when i open this folder in Visual Studio Code , i know it must show the current branch name , in the bottom left side .
Does anybody know how to do this ? To show the branch name in Visual Studio Code ?
Thank you very much.
-- > I added Sourcetree`s bin folder to the PATH and now everything is working ok :D . Sourcetree uses embed git so you have to add it to the window path

Assuming you have git installed all you do is go to View->Show Status Bar (as seen below). It will then show your current branch on the bottom of your current editor window.

For windows:
The easiest thing would be to change your integrated terminal shell from Powershell to Git Bash. You can do that by going to File > Preferences > Setting and changing the integrated terminal shell, as illustrated below:
For mac navigate to:
Code> Preferences> settings> Search for 'terminal'

In the docs it says:
Note: VS Code will leverage your machine's Git installation, so you
need to install Git first before you get these features. Make sure you
install at least version 2.0.0.
So there needs to be a Git on your system to get it working. Using the embedded Git from your Sourcetree installation will probably work, but might not be the cleanest solution. The Git in my Sourcetree installation (on a Mac) is about 3 years old (2.2.1). On a Mac there is also a Git preinstalled though (2.11.0), so here it works out of the box.

It's not clear if you're looking for display on the command-line [prompt] or in the VSCode UI.
There's this alternative view provided by the sidebar plugin that fits the bill when the Source Control Repositories option is checked (right-click on the topmost Source Control header):
UI branch controls!

In year 2022
From top menu, select and check View > Appearance > Status bar
Status bar appears at bottom of VS Code Window
Branch displays in Status bar on left-side

If you would also like to show the working branch in the Visual code Terminal Window, Try installing posh-git from chocolatey, you get all the git summarycolor codings and tab completion with the branch name in highlighted colors. If you are running a Powershell version less than 6, make sure to set execution policies above Restricted.

Related

Terminal Git Status showing different than Visual Studio status

I've been at this for a couple of days and I can't figure this out.
When I run git status on my terminal, it's giving me a different result than what my visual studio 2022 shows me. I think this all started when i added git lfs to my repo using brew so it doesnt track the larger files i have.
For example, in my terminal, it's showing: . Usually they show the same files always and never have an issue.
but then on the same branch in visual studio 2022, it's showing, it's showing this:
so far, I've tried:
Restarting my computer and visual studio(I had to try)
Using the sync button (next to the pushbutton) in visual studio.
Running git remote update on my terminal
I can't find anything else on SO to try.
Any and all help or direction is appreciated!
Check your .gitattributes files; since you added git lfs, it tracks the large file extensions with the .gitattributes file. That may be the reason why Visual Studio is not tracking those files, but your git terminal does.
There is a bug which i also face in visual studio.
Sometimes the VSCode cannot track the files which are updated.
what you can try is update the visual studio to see if the bug is fixed or not.
Mine was resolved by updating the VS.
PS: try using GitLens for a broader view of git.

C/C++ Code navigation not working in vscode remote development

Tried to access a remote project (from Linux environment) over vscode remote development environment, followed all the necessary steps mentioned in https://code.visualstudio.com/docs/remote/remote-overview, Able to see the files and folder structure but unable to navigate the source code. Tried "Goto Definition"(F12) and Ctrl+ Click also not working
Tried to set max watch value to fs.inotify.max_user_watches=524288 still issue remain same
Once I reload the extensions it worked fine. I installed C/C++ IntelliSense from Microsoft and Austin

Visual Studio Code source control not showing changes

Visual Studio Code source control panel is empty when I click on it. Nothing to expand and nothing to click on.
Things I've tried:
Uninstalled/Reinstalled Git
Uninstall/Reinstalled VS Code
Removed extensions folder
Open your project with cmd.
> cd your-folder-location
> code . -n
It worked for me
Dude, just lost an hour because my SCM in VSCode randomly stopped showing anything today. I restarted everything, tried git init, everything on the forums. Made sure Git built in extension is enabled, mine was already enabled so I was totally lost.
All I had to do was disable and then reenable the built in Git extension. and it fixed it.
Go to Extensions.
Filter by "built in".
Click the gear icon by Git, and click disable.
Then click it again, and click enable.
Here is a screenshot reference
In my case, somehow, the Source Control Repositories option, available under the 3 dots ... on the SOURCE CONTROL tab, was no longer selected.
All I had to do was press the ... and select Source Control Repositories, then select the correct repo, and all the changes were again listed.
I had a similar issue. It seems vs code has two source control extensions. When I clicked View -> SCM it opened an extension with changes displaying.
source control extension 1
source control extension 2
I had this problem 2-3 times for the last 2 years (OS -> Linux Mint). The changes on any file didn't appear to the source control nor have they been marked on the line I've edited. When manually go to "Source control" and click on the refresh button they appear but the lines that I had change didn't light up (there were no visual marking on the files after editing them). This happened when I switched to a different branch while the workspace was open to the 2 monitors at the same time. Or when working on several projects (opened 2-3 or more VS Code instances). The scariest thing was that it didn't work not only for one repository(project) but for all of them. I've read alot on the subject and tried everything that I found and think of. There is some issue with git path mapping or something.
The thing that I tried:
reload VS Code
restarting VS Code
disable all extensions
enable/disable all git related options in (file -> preferences -> settings)
deleting (folders and files) and cloning the repository
updating git
removing and installing git
restarting PC (don't judge me I was desperate)
But the only solution that worked for me was:
open VS Code (if open, don't close it)
go to the directory where you keep your repositories (not from VS Code but from you file explorer).
go one folder above it (if you are in .../{{some folder}}/{{you repos}}, go to ../{{some folder}})
then open you repositories containing folder (/{{you repos}}) by right click -> open with VS Code
wait until everything loads. The Source Control will mark alot of changes, don't worry about it.
then close VS Code (all windows (instances), because it will open a new instance)
after that go to the directory where you keep your repositories again and right click and open with VS code the repository of you choice. Now at this point the Source control will start working properly.
What worked for me was going to my "code" folder where I keep all my repos, right-clicking on the folder containing the repo I want and opening that folder with VS Code.
The VS Code window for this specific repo was closed. I did have another window for a different repo open. As soon as the window opened, the changes showed up in source control and I was able to commit, push and everything else like normal.
I faced this problem when I opened a repo in a directory inside symlink.
My solution: just open this directory in original destination without any symlinks
I had this problem in a repository not as a problem from config but because I had a coverage folder with thousands of files not tracked and it seemed to slow the process of checking that out too much.
So I added that folder to .gitignore and it started working again.
Restating my Vscode And Giving time to load properly Solved my Problem
I had the same problem. What I did was:
Open another folder with File -> Open Folder...
Close the VSC
Open VSC
Open the original folder with File -> Open Folder...
After this I saw that the source control started loading and my changes came back.
Hope this works for you.
I couldn't see any changes in while trying git status. I opened changed files in text editor and they were not changed either. That lead me to conclusion that changes can't be seen by the system (and therefore by git).
The Autosave option was disabled, simply saving the changes helped.
That was my beginning with VSC, in Pycharm never had such problem.
I had this problem, because I was changing files one folder down from where I opened Visual Studio Code.
Solution- open Visual Studio Code without a location, File/Open Folder - open the folder I am directly working out of.
Unstaged changes now show in the direct folder I'm working in. Unstage changes previously auto-staged by Visual Studio Code when working on a nested project directory to see them (open a Terminal and run git reset).
I encountered the same issue, and I fixed that by removing the files.watcherExclude property in settings.json file.
Because the value of files.watcherExclude became { "**/**/*": true } somehow.
// settings.json
// remove or comment next line
// files.watcherExclude: { "**/**/*": true }
For me, the files were in WSL (Windows subsystem for linux) but I was not opening the folder as such.
in the bottom left, click the green >< symbol, then click "reopen folder in WSL"
VSC remote mode image
presto.
Go to View -> Terminal
cd to root folder, and run git status and see if you have any errors
I had a unsafe repository fatat error, as my repo was on a network drive. Did as suggested by git to add an exception and it fixed the issue.
close vscode
moved local Code config folder as backup (~/.config/Code/)
reopen vscode (this will still show problem)
close and reopen vscode (this will show db re-write issue but it will re-create config folder.)
this solved my problem. this reset many of my settings but It can be checked from config backup.
In setting check Git: Autorefresh
I experience this problem when I right click a folder and open it up with VS code. Instead now I start VS code from the start menu and after that I use File -> Open Folder option.
I experienced this issue with VSCode V1.70.1, all I did is just closing VSCode completely and open a new instance and I could find git changes appears simultaneously as expected.
If running into this issue on a Mac, make sure you are running your instance of Visual Studio Code from your Applications folder and not your Downloads folder. I managed to fire up an instance from the wrong folder and this prevented my Source Control from being able to properly load git info and also caused Visual Studio updates to fail. More on the issue can be found here.
Here is another possible solution for Linux users:
In my case, it was only not showing lines changed with the file open. Source control tab was showing fine.
I have a symlink from /var/www to /mnt/{hdd-uuid}/www. When I created my workspace, it was using the path /var/www/project-folder, instead of the full path, and this was giving me the error.
I opened my .code-workpsace file in another text editor and changed the references in the JSON from ../../../../var/www/project-folder to /mnt/{hdd-uuid}/www/project-folder, then reopen VS Code. Close all file tabs open and, when you open again a modified file it will show the lines changed.
It is possible that you need to trust the repo again.
Try opening project or folder which contains git files. Later try opening your wanted folder. This sorted the issue for me.
Double-check git is actually installed on your system. I just did a fresh install of Windows 11 the other day, and although one of the development tools I installed thereafter downloaded and supposedly installed git in Windows, actually, it never installed it. Fail!
I fixed this issue by toggled-on the AutoSave feature in VSCode via File > AutoSave. I noticed that the badge on the github does not show up until the file is actually saved first.
What worked for me was that I was forgetting to save, so just enabled autosave option.
File > Auto Save (check)
Open Visual Studio code -> View -> Appearance -> Show activity bar

GitHub clone to desktop uses TortoiseGit instead of GitHub Desktop

When i try to clone a repository to desktop the default app for cloning has suddenly became TortoiseGit instead of GitHub. Anyone with a fix?
The following fix is a permanent solution for this issue that also withstands TortoisGit-updates/repairs.
It adds GitHubDesktop's protocol-associations the way described in https://learn.microsoft.com/en-us/windows/win32/shell/default-programs.
Add to the registry (You can save this content as .reg file and double-click it to auto-import these keys into registry):
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\GitHubDesktop]
[HKEY_LOCAL_MACHINE\SOFTWARE\GitHubDesktop\Capabilities]
[HKEY_LOCAL_MACHINE\SOFTWARE\GitHubDesktop\Capabilities\UrlAssociations]
"github-windows"="github-windows"
"x-github-client"="x-github-client"
[HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications]
"GitHubDesktop"="Software\\GitHubDesktop\\Capabilities"
Reboot or on a windows-server sign-out and log-in.
The next time a project is cloned from github, a message-box popped-up asking to pick an app.
GitHubDesktop will now also be available in the Windows settings: Choose default apps by protocol. So it can be recovered with Windows settings, if TortoisGit (or another app) was chosen as default handler for GitHub-clone.
I also opened a new error at GitHubDesktop-development: https://github.com/desktop/desktop/issues/8258
There was a bug in 2.6.0 which made TortoiseGit the default if the github handler was enabled on installation.
To fix this, go to the default programs settings in Windows, open the file-type associations dialog and set github-windows and x-github-client back to the official github client. Maybe you have to update to TortoiseGit 2.7.0 first.
cf. https://www.thewindowsclub.com/change-file-associations-windows
You could try whether the hard way works: (Store this as a .reg file and import it, you need to madjust the paths)
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\github-windows]
[HKEY_CLASSES_ROOT\github-windows]
"URL Protocol"=""
#="URL:github-windows"
[HKEY_CLASSES_ROOT\github-windows\shell\open\command]
#="\"C:\\Users\\USERNAME\\AppData\\Local\\GitHubDesktop\\app-1.4.2\\GitHubDesktop.exe\" --protocol-launcher \"%1\""
[-HKEY_CLASSES_ROOT\x-github-client]
[HKEY_CLASSES_ROOT\x-github-client]
"URL Protocol"=""
#="URL:x-github-client"
[HKEY_CLASSES_ROOT\x-github-client\shell\open\command]
#="\"C:\\Users\\USERNAME\\AppData\\Local\\GitHubDesktop\\app-1.4.2\\GitHubDesktop.exe\" --protocol-launcher \"%1\""
change windows registry is not working.
I have met the same problem and the registry is all right,but github desktop wont come out.
As a software developer,I used url protocol once.I cannt understand why Windows setting is not related to the ROOT registry . I would appreciate a comment.
here is how i solve the problem:
After uninstall tortoise and reinstall github. Chrome works fine.
When you install tortoise,be careful with this setting:
but even if you unchecked this,x-github-client is registed to tortoisegit client again.
You can check it in your windows setting of default apps - choose default apps by protocal.
So i think this is a bug for tortisegit.
I use tortoisegit 2.7.0 and win10 1809.
If you really want github desktop to popup , you should not install tortoisegit
This is based on tobias.loew answer:
If you don't have this line at the start:
Windows Registry Editor Version 5.00
Script won't compile
Create github.reg file:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\GitHubDesktop]
[HKEY_LOCAL_MACHINE\SOFTWARE\GitHubDesktop\Capabilities]
[HKEY_LOCAL_MACHINE\SOFTWARE\GitHubDesktop\Capabilities\UrlAssociations]
"github-windows"="github-windows"
"x-github-client"="x-github-client"
[HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications]
"GitHubDesktop"="Software\\GitHubDesktop\\Capabilities"
Put this in a file called github.reg and then double click it.

Android Studio Checkout Github Error "CreateProcess=2" (Windows)

Today I've tried to checkout my Github project using brand new Android Studio and ended up with this nasty error :
Why things just never work out of the box ...?
I've solved the problem , and I will explain how :
Download Github For Windows client and install it.
After The client successfully installed , connect it with your github account.It should be easy , just follow the wizard.
Then you should add git.exe location to your "Path Variable". The location you should add will probably be something like :
C:\Users\Your_Username\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\bin
Alternatively , if you don't want to add to environment variables. You can open the android studio and go to :
Settings -> Version Control -> Git
In text box next to "Path to Git Executable" you will see "git.exe" , just give it a full path like so :
C:\Users\Your_Username\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\bin\git.exe
EDIT :
For latest Github for windows versions some can find the git.exe under "...\cmd\git.exe" rather than "...\bin\git.exe".
I found what I think is a faster solution.
Install Git for Windows from here: http://git-scm.com/download/win
That automatically adds its path to the system variable during installation if you tell the installer to do so (it asks for that). So you don't have to edit anything manually.
Just close and restart Android Studio if it's open and you're ready to go.
I am using Windows 10 OS and GitHub Desktop version 1.0.9.
For the new Github For Windows, git.exe is present in the below location.
%LOCALAPPDATA%\GitHubDesktop\app-[gitdesktop-version]\resources\app\git\cmd\git.exe
Example:
%LOCALAPPDATA%\GitHubDesktop\app-1.0.9\resources\app\git\cmd
If you have downloaded Github Desktop Client 1.0.9 then the path for git.exe will be
C:\Users\Username\AppData\Local\GitHubDesktop\app-1.0.9\resources\app\git\cmd\git.exe
I faced same issue in android studio 3.2.1, solved the issue by setting git path in System Environment variable
C:\Program Files\Git\bin\,C:\Program Files\Git\bin\
And I imported the project once again and solved the issue!!!
Note : Check your android studio git settings has properly set the correct path to git.exe
Steps:
1) Download git for windows https://git-scm.com/downloads
2) Install downloaded git with default setup
3) From Android Studio close if any project is open then Click on Configure -> Settings -> Version Control -> Git
4) Change Path to Git executable : git.exe to C:\Program Files\Git\cmd\git.exe
5) Apply and Ok
6) Try to clone from Check out project from Version Control
7) Done
for Android Studio 3.0.1, you can config GitHub path for following path:
File > Setting > Version Control
List item
Click "+" on the top-right conor to open "Add VCS Directory Mapping"
Click "Configure VCS" to open "Version Control Configurations"
Click "Git" then you'll see Path to Git executable]
Input : C:\Users[you user name]\AppData\Local\GitHub\PortableGit_d7effa1a4a322478cd29c826b52a0c118ad3db11\cmd\git.exe
Test it
enter image description here
I encountered a similar error with RubyMine 2016.3 recently, wherein any attempts at checkout or export to Github were met with "Cannot run program 'C:\Program Files (x86)\Git\cmd\git.exe': CreateProcess error=2, The system cannot find the file specified"
As an alternative solution for this problem, other than editing the Path system variable, you can try searching through the program files of Android Studio for a git.xml file and editing the myPathToGit option to match the actual location of git.exe on your computer. This is how I fixed this similar issue in RubyMine.
Posting this solution here for the sake of posterity.
I had this issue on Mac. I simply quit Android Studio and restarted it, and for some reason had no further issues.