Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019
Visual Studio 2019 | Visual Studio 2022
In Visual Studio, you can view and configure several Git-related settings and preferences. For example, you can set your name and email address for commit metadata, specify your preferred diff and merge tools, and set the default folder path for repo clones.
Git settings and preferences in Visual Studio fall into two main categories:
Git Global Settings, which apply to all Git repos for the current user.
Git Repository Settings, which apply to the active Git repo.
Within those categories, settings can be:
Git configuration file settings, which you can view and modify either in Visual Studio, on the command line, or by editing a Git configuration file. Examples of Git configuration file settings are user name, email address, and remote aliases. Git stores settings in system, global, and local Git configuration files:
System Git configuration file settings apply to all users and repos on your computer.
Global Git configuration file settings apply to all repos for the current user. Global settings take precedence over system settings.
Local Git configuration file settings apply to the local repo that contains the local Git configuration file. System settings take precedence over global settings.
Visual Studio Git-related settings, which are Visual Studio settings that relate to Git but aren't stored in any Git configuration file. You can only view and modify these settings in Visual Studio. An example of one of these settings is the default folder path where Visual Studio clones repos.
- View code in private projects: At least Basic access. - Clone or contribute to code in private projects: Member of the Contributors security group or corresponding permissions in the project. - Set branch or repository permissions: Manage permissions permissions for the branch or repository. - Change default branch: Edit policies permissions for the repository. - Import a repository: Member of the Project Administrators security group or Git project-level Create repository permission set to Allow. For more information, see Set Git repository permissions.
- View code: At least Basic access. - Clone or contribute to code: Member of the Contributors security group or corresponding permissions in the project.
Visual Studio 2022 provides a Git version control experience by using the Git menu, Git Changes, and through context menus in Solution Explorer. Visual Studio 2019 version 16.8 also offers the Team Explorer Git user interface. For more information, see the Visual Studio 2019 - Team Explorer tab.
To configure Git settings in Visual Studio, choose Git > Settings from the menu bar to open the Options view.
In the Options view, choose Git Global Settings to view settings that apply to all your repos.
Or, in the Options view, choose Git Repository Settings > General to view settings that only apply to the current Visual Studio project repo.
Visual Studio 2019 provides a Git version control experience by using the Git menu, Git Changes, and through context menus in Solution Explorer.
To configure Git settings in Visual Studio, choose Git > Settings from the menu bar to open the Options view.
In the Options view, choose Git Global Settings to view settings that apply to all your repos.
Or, in the Options view, choose Git Repository Settings > General to view settings that only apply to the current Visual Studio project repo.
Visual Studio 2019 version 16.8 and later versions provides a Git version control experience while maintaining the Team Explorer Git user interface. To use Team Explorer, uncheck Tools > Options > Preview Features > New Git user experience from the menu bar. You can use Git features from either interface interchangeably.
To configure Git settings in Visual Studio, choose Settings from Team Explorer to open the Settings view.
In the Settings view, choose Global Settings to view settings that apply to all your repos, or choose Repository Settings to view the settings that apply to the current Visual Studio project repo.
To view all settings across system, global, and local Git configuration files, run:
Console
git config --list
Piezīme
git config --list output won't include local Git configuration file settings unless you run the command at the root folder of a local repo.
System Git configuration file settings apply to all users and repos on your computer. To view those settings, run:
Console
git config --list --system
Global Git configuration file settings apply to the current user and their repos. To view those settings, run:
Console
git config --list --global
Local Git configuration file settings apply to a local repo. To view those settings, run the following command at the root folder of a repo.
Console
git config --list --local
Modify Git configuration file settings
You can view and edit Git configuration settings in Visual Studio or by directly editing the applicable Git configuration file. For more information about Git configuration file settings, see Customizing Git and git-config documentation. In the following sections, we discuss how you can edit each of the listed Git configuration file settings:
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the name and email settings for the current user.
Or, choose Git Repository Settings > General to edit the name and email settings for the current Visual Studio project repo.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the name and email settings for the current user.
Or, choose Git Repository Settings > General to edit the name and email settings for the current Visual Studio project repo.
In Team Explorer, choose Settings to open the Settings view. Then choose Global Settings to edit the name and email settings for the current user.
Or, choose Repository Settings to edit the name and email settings for the current Visual Studio project repo.
To set your user name and email in a local Git configuration file, run the following commands in the root folder of the local repo.
By default, this command writes to the local Git configuration file. To write to another file, pass one of the following options: --system, --global, or --file <filepath> to write to a file. For example, to write to the global Git configuration file for the current user, run:
You can tell Git to prune remote branches during every fetch to remove stale remote-tracking branches in your local repo that no longer exist on the corresponding remote repo.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Prune remote branches during fetch option for the current user.
Or, choose Git Repository Settings > General to edit the Prune remote branches during fetch setting for the current Visual Studio project repo.
Valid values are:
True (recommended)
False
Unset (default)
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Prune remote branches during fetch option for the current user.
Or, choose Git Repository Settings > General to edit the Prune remote branches during fetch setting for the current Visual Studio project repo.
Valid values are:
True (recommended)
False
Unset (default)
The Prune remote branches during fetch setting corresponds to the git config fetch.prune command. You can specify this setting at the global or repo scope. To keep remote tracking branch lists clean and up to date for all your repos, we recommend that you enable this option at the global level.
In Team Explorer, choose Settings to open the Settings view. Then choose Global Settings to edit the Prune remote branches during fetch option for the current user.
Or, choose Repository Settings to edit the Prune remote branches during fetch setting for the current Visual Studio project repo.
Valid values are:
True (recommended)
False
Unset (default)
To keep remote tracking branch lists clean and up to date for all your repos, we recommend that you enable this option at the global level, by running:
Console
git config --global fetch.prune true
Valid values are:
true (recommended)
false (default when fetch.prune isn't specified in Git configuration files)
Rebase local branch when pulling
You can choose to rebase your local branch when pulling to replay the changes in your local branch on top of the remote branch history.
The Rebase local branch when pulling setting corresponds to the git config pull.rebase command. You can specify this setting at the global or repo scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Rebase local branch when pulling option for the current user.
Or, choose Git Repository Settings > General to edit the Rebase local branch when pulling option for the current Visual Studio project repo.
Valid values are:
True: rebase the current branch on top of the remote branch after fetch.
False: merge the remote branch into the current branch.
Merges: rebase without flattening locally created merge commits.
Unset (default): unless specified otherwise in a Git configuration file, merge the remote branch into the current branch.
The Rebase local branch when pulling setting corresponds to the git config pull.rebase command. You can specify this setting at the global or repo scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Rebase local branch when pulling option for the current user.
Or, choose Git Repository Settings > General to edit the Rebase local branch when pulling option for the current Visual Studio project repo.
Valid values are:
True: rebase the current branch on top of the remote branch after fetch.
False: merge the remote branch into the current branch.
Merges: rebase without flattening locally created merge commits.
Unset (default): unless specified otherwise in a Git configuration file, merge the remote branch into the current branch.
The Rebase local branch when pulling setting corresponds to the git config pull.rebase command. You can specify this setting at the global or repo scope.
In Team Explorer, choose Settings to open the Settings view. Then choose Global Settings to edit the Rebase local branch when pulling option for the current user.
Or, choose Repository Settings to edit the Rebase local branch when pulling option for the current Visual Studio project repo.
Valid values are:
True: rebase the current branch on top of the remote branch after fetch.
False: merge the remote branch into the current branch.
Merges: rebase without flattening locally created merge commits.
Unset (default): unless specified otherwise in a Git configuration file, merge the remote branch into the current branch.
The Cryptographic network provider setting corresponds to the git config http.sslBackend command. This setting is only available at the global scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Cryptographic network provider option for the current user.
Secure Channel: use Secure Channel for TLS and SSL protocols. Secure Channel is the native Windows solution that contains a set of security protocols that provide identity authentication and secure, private communication through encryption.
Unset (default): if this setting is unset, the Cryptographic network provider defaults to OpenSSL.
The Cryptographic network provider setting corresponds to the git config http.sslBackend command. This setting is only available at the global scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Cryptographic network provider option for the current user.
Secure Channel: use Secure Channel for TLS and SSL protocols. Secure Channel is the native Windows solution that contains a set of security protocols that provide identity authentication and secure, private communication through encryption.
Unset (default): if this setting is unset, the Cryptographic network provider defaults to OpenSSL.
The Cryptographic network provider setting corresponds to the git config http.sslBackend command. This setting is only available at the global scope.
In Team Explorer, choose Settings to open the Settings view. Then choose Global Settings to edit the Cryptographic network provider option for the current user.
Secure Channel: use Secure Channel for TLS and SSL protocols. Secure Channel is the native Windows solution that contains a set of security protocols that provide identity authentication and secure, private communication through encryption.
Unset (default): if this setting is unset, the Cryptographic network provider defaults to OpenSSL.
schannel: use Secure Channel for TLS and SSL protocols. Secure Channel is the native Windows solution that contains a set of security protocols that provide identity authentication and secure, private communication through encryption.
Credential helper
When Visual Studio performs a remote Git operation, the remote endpoint might reject the request because it requires credentials for the request. When that happens, Git invokes a credential helper to obtain the necessary credentials and then retries the request. You can specify the credential helper that Git will use.
Unset (default): if this setting is unset, the credential helper set in the system config is used. As of Git for Windows 2.29, the default credential helper is GCM Core.
The Credential helper setting corresponds to the git config credential.helper command. This setting is only available at the global scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view to configure this setting.
Set Credential helper to the desired value, and select OK to save.
Unset (default): if this setting is unset, the credential helper set in the system config is used. As of Git for Windows 2.29, the default credential helper is GCM Core.
Use the Visual Studio 2019 - Git menu procedure.
Open a command prompt and run:
Console
git config credential.helper [cache|store]
Valid values are:
cache: in-memory credential storage.
store: credentials stored in a plain-text file .git-credentials or specify a different file by using the --file option.
The diff and merge tool settings correspond to the git config diff.tool and git config merge.tool commands. You can set Visual Studio as the merge or diff tool, or configure other diff and merge tools from the Git command line. You can specify diff and merge tool settings at the global or repository scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the diff and merge tools settings.
Set the diff and merge tool settings to the desired value, and select OK to save.
Or, choose Git Repository Settings > General to edit the diff and merge tool settings for the current Visual Studio project repo.
Valid diff and merge tools are:
Visual Studio
None (default)
To configure other diff and merge tool settings, use the Git command line.
The diff and merge tool settings correspond to the git config diff.tool and git config merge.tool commands. You can set Visual Studio as the merge or diff tool, or configure other diff and merge tools from the Git command line. You can specify diff and merge tool settings at the global or repository scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the diff and merge tools settings.
Set the diff and merge tool settings to the desired value, and select OK to save.
Or, choose Git Repository Settings > General to edit the diff and merge tool settings for the current Visual Studio project repo.
Valid diff and merge tools are:
Visual Studio
None (default)
To configure other diff and merge tool settings, use the Git command line.
The diff and merge tool settings correspond to the git config diff.tool and git config merge.tool commands. You can set Visual Studio as the merge or diff tool, or configure other diff and merge tools from the Git command line. You can specify diff and merge tool settings at the global or repository scope.
In Team Explorer, choose Settings to open the Settings view. Then choose Global Settings to edit the diff and merge tool settings for the current user.
Or, choose Repository Settings to edit the diff and merge tool settings for the current Visual Studio project repo.
Valid diff and merge tools are:
Visual Studio
None (default)
To configure other diff and merge tool settings, use the Git command line.
To get a list of valid diff tools, run: git difftool --tool-help
To get a list of valid merge tools, run: git mergetool --tool-help
For more information on diff and merge tool options, see diff.tool and merge.tool.
Remotes
You can use the Remotes pane under Git Repository Settings to add, edit, or remove remotes for your repository. This setting corresponds to the git remote add command. The Remotes pane is only available at the repository scope.
When you clone a remote repo, Git assigns the alias origin as shorthand for the URL of the remote repo you cloned. For convenience, you can add another alias named upstream for the repo you forked from, which is referred to as the upstream repo. The following steps describe how to add an upstream alias.
To add an upstream alias in Visual Studio, follow these steps:
Choose Tools > Options from the menu bar to open the Options window. Select Source Control > Git Repository Settings > Remotes, and then choose Add to open the Add Remote dialog.
In the Add Remote dialog, add a new remote called upstream and enter the Git clone URL of the repo you forked. Then, choose Save.
To add an upstream alias in Visual Studio, follow these steps:
Choose Tools > Options from the menu bar to open the Options window. Select Source Control > Git Repository Settings > Remotes, and then choose Add to open the Add Remote dialog.
In the Add Remote dialog, add a new remote called upstream and enter the Git clone URL of the repo you forked. Then, choose Save.
Use the Visual Studio 2019 - Git menu procedure.
On the command line, navigate to the root folder of your local repo, and then run the following command to add a new remote named upstream. Replace <clone URL> with the Git clone URL of the repo you forked.
Console
git remote add upstream <clone URL>
For example, git remote add upstream https://fiber-teams@dev.azure.com/fiber-teams/FiberTests/_git/FiberTests adds an upstream alias.
To edit an existing upstream alias, run the following command:
Console
git remote set-url upstream <clone URL>
Padoms
For convenience, you can use the origin and upstream aliases instead of their corresponding URLs in your Git commands.
For more information about configuring remotes, see git remote.
Other settings
To view all of other Git configuration settings, you can open and view the Git configuration files themselves, or you can run git config --list to display the settings.
Modify Visual Studio Git-related settings
The following settings manage Git-related preferences in Visual Studio. You can only view and edit these settings from within Visual Studio.
For more information about how to access Visual Studio Git-related settings, see Explore Git settings. Next, we discuss how you can edit each of these Visual Studio Git-related settings.
Default repository location
You can set the default repository folder in which Visual Studio will clone repos.
The Default repository location setting is only available at the global scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Default repository location setting.
Set the default repository location, and select OK to save.
The Default repository location setting is only available at the global scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Default repository location setting.
Set the default repository location, and select OK to save.
The Default repository location setting is only available at the global scope.
In Team Explorer, choose Settings to open the Settings view. Then choose Global Settings to set the default repository location for the current user.
You can only view and modify this setting in Visual Studio.
Close open solutions not under Git when opening a repository
By default, Visual Studio closes any open solution or folder in a Git repo when you switch to a different repo. The Close open solutions not under Git when opening a repository setting keeps the open solution or folder consistent with the selected repo. However, if your solution or folder isn't inside a repo, you might want to keep the solution open when you switch repository. You can do that with this setting.
The Close open solutions not under Git when opening a repository setting is only available at the global scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view to configure this setting.
Set the default repository location, and select OK to save.
Valid values are:
Yes: when you switch repo, Visual Studio closes any open solution.
No: when you switch repo and the current solution or folder isn't under Git, Visual Studio will keep the solution or folder open.
Always ask (default): when you switch repo and the current solution or folder isn't under Git, Visual Studio will ask whether you want to keep the current solution open.
The Close open solutions not under Git when opening a repository setting is only available at the global scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view to configure this setting.
Set the default repository location, and select OK to save.
Valid values are:
Yes: when you switch repo, Visual Studio closes any open solution.
No: when you switch repo and the current solution or folder isn't under Git, Visual Studio will keep the solution or folder open.
Always ask (default): when you switch repo and the current solution or folder isn't under Git, Visual Studio will ask whether you want to keep the current solution open.
The Close open solutions not under Git when opening a repository setting is only available at the global scope.
Use the Visual Studio 2019 - Git menu procedure.
You can only view and modify this setting in Visual Studio 2019 or later.
Enable download of author images from third-party sources
When enabled, Visual Studio will download an author image from the Gravatar image service for display in the commit and history views. If you haven't configured a Gravatar image, the Gravatar image service will return a randomly generated image for you.
Svarīgi
To provide author images in the commit and history views, Visual Studio creates an MD5 hash using the author email address stored in the active repository and sends that hash to Gravatar. If Gravatar finds a user with a matching hash, Visual Studio will retrieve and display the user's image. Microsoft doesn't record or share email addresses with Gravatar or any other third-party.
The Enable download of author images from third-party sources setting is only available at the global scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Enable download of author images from third-party sources setting.
Choose whether to enable download of author images from third-party sources, and select OK to save.
The Enable download of author images from third-party sources setting is only available at the global scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Enable download of author images from third-party sources setting.
Choose whether to enable download of author images from third-party sources, and select OK to save.
The Enable download of author images from third-party sources setting is only available at the global scope.
In Team Explorer, choose Settings to open the Settings view. Then choose Global Settings to choose whether to enable download of author images from third-party sources.
You can only view and modify this setting in Visual Studio.
Commit changes after merge by default
With Commit changes after merge by default enabled, Git automatically creates a new commit on branch merge.
When checked, all git merge commands issued by Visual Studio are run with the --commit option.
When unchecked, all git merge commands issued by Visual Studio are run with the --no-commit --no-ff options.
The Commit changes after merge by default setting is only available at the global scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Commit changes after merge by default setting.
Choose whether to commit changes after merge by default, and select OK to save.
The Commit changes after merge by default setting is only available at the global scope.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Commit changes after merge by default setting.
Choose whether to commit changes after merge by default, and select OK to save.
The Commit changes after merge by default setting is only available at the global scope.
In Team Explorer, choose Settings to open the Settings view. Then choose Global Settings to choose whether to commit changes after merge by default.
You can only view and modify this setting in Visual Studio.
Enable push --force-with-lease
With this setting enabled, you can push changes that overwrite work in a remote branch—if no one else has pushed to the remote branch since your last pull.
The Enable push --force-with-lease option corresponds to the push --force-with-lease command. This setting is only available at the global scope. By default, Enable push --force-with-lease is disabled.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Enable push --force-with-lease setting.
Choose whether to enable push --force-with-lease, and select OK to save.
The Enable push --force-with-lease option corresponds to the push --force-with-lease command. This setting is only available at the global scope. By default, Enable push --force-with-lease is disabled.
From the Git menu, choose Git > Settings and then select the Git Global Settings view. That view contains the Enable push --force-with-lease setting.
Choose whether to enable push --force-with-lease, and select OK to save.
The Enable push --force option corresponds to the push --force command. This setting is only available at the global scope. By default, this setting is disabled.
In Team Explorer, choose Settings to open the Settings view. Then choose Global Settings to choose whether to enable push --force.
You can only view and modify this setting in Visual Studio.
Open folder in Solution Explorer when opening a Git repository
When enabled and you open a Git repo in Visual Studio, Visual Studio will scan the repository folder for solutions, CMakeLists.txt, or other view files and display them as a list in Solution Explorer. You can then load a solution or view the contents of a folder. This setting is enabled by default.
When disabled and you open a Git repo in Visual Studio, Visual Studio won't open the repo folder in Solution Explorer and is only a Git repo manager.
From the Git menu, choose Git > Settings and then select the Git Global Settings view to configure this setting.
Choose whether to enable Open folder in Solution Explorer when opening a Git repository, and select OK to save.
From the Git menu, choose Git > Settings and then select the Git Global Settings view to configure this setting.
Choose whether to enable Open folder in Solution Explorer when opening a Git repository, and select OK to save.
Use the Visual Studio 2019 - Git menu procedure.
You can only view and modify this setting in Visual Studio 2019 or later.
Automatically load the solution when opening a Git repository
The Automatically load the solution when opening a Git repository setting is applicable only if the Open folder in Solution Explorer when opening a Git repository setting is also enabled. When you open a Git repository in Visual Studio, and the subsequent folder scan detects there's only one solution present in your repository, then Visual Studio automatically loads that solution. If you turn off this setting, then Solution Explorer will display the single solution present in the repository in the list of views, but won't load the solution. This setting is disabled by default
From the Git menu, choose Git > Settings and then select the Git Global Settings view to configure this setting.
Choose whether to enable Automatically load the solution when opening a Git repository, and select OK to save.
From the Git menu, choose Git > Settings and then select the Git Global Settings view to configure this setting.
Choose whether to enable Automatically load the solution when opening a Git repository, and select OK to save.
Use the Visual Studio 2019 - Git menu procedure.
You can only view and modify this setting in Visual Studio 2019 or later.
Automatically check out branches with double-click or the Enter key
The Git Repository window has a list of branches displayed in a tree structure. Select a branch to switch the commit history pane to display the commits for that branch. To check out a branch, right-click to open the context menu and choose Checkout. With the Automatically check out branches with double-click or the Enter key setting enabled, you can double-click or select the Enter key to check out a branch and display its commits.
The option to add or edit a gitignore or gitattributes file is only available at the repository scope.
From the Git menu, choose Git > Settings and choose the Git Repository Settings > General view. That view contains options to edit gitignore or gitattributes files.
Choose Edit to open the ignore or attribute file in a Visual Studio editor window.
The option to add or edit a gitignore or gitattributes file is only available at the repository scope.
From the Git menu, choose Git > Settings and choose the Git Repository Settings > General view. That view contains options to edit gitignore or gitattributes files.
Choose Edit to open the ignore or attribute file in a Visual Studio editor window.
The option to add or edit a gitignore or gitattributes file is only available at the repository scope.
In Team Explorer, choose Settings to open the Settings view. In that view, select Repository and choose Edit to open the ignore or attribute file for the current project repo in a Visual Studio editor window.
Open and edit the .gitignore or .gitattributes files in an editor.
For information about how to configure .gitignore and .gitattributes files, see gitignore and gitattributes.
Pievienojieties meetup sērijai, lai kopā ar citiem izstrādātājiem un ekspertiem izveidotu mērogojamus AI risinājumus, kuru pamatā ir reālas lietošanas gadījumi.