Troubleshoot source control

Use this article to resolve common Git problems in Visual Studio Code. Start with the symptom that matches your problem, then use the Git Output window to collect more information if the suggested fix doesn't resolve it.

Push, pull, or sync doesn't finish

A Git operation that doesn't finish often indicates that Git is waiting for authentication but the credential prompt isn't visible.

  1. Open the Git Output window and check the most recent command for an authentication error.

  2. Configure a Git credential helper for your operating system.

  3. Run the operation again and complete any sign-in prompt.

Git Credential Manager is the recommended credential helper for Windows, macOS, and Linux. Git for Windows includes Git Credential Manager.

Git authentication prompts appear repeatedly

VS Code automatically fetches remote changes to show incoming commits. The authentication prompt comes from your Git credential helper, not from VS Code.

Configure a Git credential helper to store your credentials. If you don't want VS Code to fetch in the background, turn off the git.autofetch Open in VS Code Open in VS Code Insiders setting.

Git actions are unavailable after initializing a repository

Push, pull, and sync require a remote repository. If you initialized a local repository, add a remote or use Publish to GitHub in the Source Control view.

After the branch has an upstream remote, VS Code makes the synchronization actions available.

VS Code reports that a repository is potentially unsafe

Git blocks operations in a repository owned by a different operating-system user. This protects you from running Git configuration or hooks from an untrusted repository.

Select Manage Unsafe Repositories in the Source Control view or notification. Review the repository location before you mark it as safe. Marking a repository as safe adds its location to Git's safe.directory configuration.

On Windows, this can happen when you clone a repository from an application running as administrator and later open it from an application that isn't running as administrator.

VS Code doesn't detect a repository in a parent folder

VS Code doesn't automatically open Git repositories in parent folders because doing so can expose changes outside the folder you intended to work with.

When VS Code detects a repository in a parent folder, use the notification or Source Control welcome view to open it. To always open repositories in parent folders, set the git.openRepositoryInParentFolders Open in VS Code Open in VS Code Insiders setting to always.

Open the Git Output window

VS Code uses your machine's Git installation for source control operations. The Git Output window records the Git executable, commands, errors, timestamps, and command duration.

Open the Git Output window in one of these ways:

  • In the Source Control view, select More Actions (...) > Show Git Output.
  • Run Git: Show Git Output from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)).
  • Open the Output panel (⇧⌘U (Windows Ctrl+Shift+U, Linux Ctrl+K Ctrl+H)) and select Git from the channel list.

Screenshot showing the Git output channel in the Output panel.

Review the most recent command and error message. The first error after the command is usually more useful than later errors that result from it.

Tip

By default, the Git Output window shows standard output only when a command fails. Use the git.commandsToLog Open in VS Code Open in VS Code Insiders setting to choose commands that should always log their standard output.

Filter and search Git logs

Use the Output panel filters to reduce the amount of log information:

  • Select a log level such as trace, debug, info, warning, or error. The default level is info.
  • Select a category such as git or repository. Select git to focus on commands executed by Git.

Screenshot showing log level and category filters in the Git Output window.

Use the search box (⌘F (Windows, Linux Ctrl+F)) to find a command, repository path, or error. The search box supports regular expressions.

Screenshot showing search results in the Git Output window.

Collect trace logs

Enable trace logging when the regular Git output doesn't contain enough information:

  1. Open the Git Output window.

  2. Select the gear icon in the Output panel header.

  3. Select Trace.

    Screenshot showing the trace log level selected in the Git Output window.

  4. Reproduce the problem and review the new log entries.

Trace logs can contain repository paths, remote URLs, branch names, and other development information. Review the output and remove sensitive information before you share it.

Next steps