title | titleSuffix | description | ms.assetid | ms.technology | ms.topic | ms.date | monikerRange |
---|---|---|---|---|---|---|---|
gitconfig files |
Azure Repos |
How gitconfig files work and are used in Visual Studio |
devops-code-git |
conceptual |
09/10/2018 |
>= tfs-2018 |
Azure Repos | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018
Visual Studio allows you to configure and view common Git settings and preferences, such as your name and email address, your preferred diff and merge tools, and more. These preferences and settings can be viewed and configured in Team Explorer on either the Global Settings page (applies to all your repositories) or the Repository Settings page (applies to the current repository).
Visual Studio allows you to configure two types of settings:
- Git settings - The settings in this section correspond to Git settings that are saved in Git configuration files. These settings can be viewed and modified in Visual Studio, but are managed by Git configuration files.
- Visual Studio settings - The settings in this section configure Git-related settings and preferences that are managed by Visual Studio.
This article shows you how to configure and view Git settings and preferences in Visual Studio, and where applicable shows you the Git command line equivalents.
[!INCLUDE temp]
-
To configure Git settings in Visual Studio, choose Settings from Team Explorer.
-
Choose Global Settings or Repository Settings to view and configure global-level or repository-level settings.
-
Visual Studio allows you to configure several common Git settings, as described in the following sections of this article. After configuring your desired settings, select Update to save the updated settings.
Visual Studio allows you to configure and check some of the most common Git configuration settings. The settings in this section can be viewed and modified in Visual Studio, but are managed by Git configuration files.
- Name and email
- Prune remote branches during fetch
- Rebase local branch when pulling
- Cryptographic network provider
- Ignore & attributes files
- Diff & merge Tools
- Remotes
- Other
Note
Git settings configured in Visual Studio's Global Settings correspond to settings in Git's user-specific configuration file, and the settings in Repository Settings correspond to settings in the repository-specific configuration file. For more information about Git configuration, see the Pro Git chapter on customizing Git, the git-config documentation, and the Pro Git reference on configuration files. To configure Git settings not exposed in Visual Studio, use the git config
command to write a value to your configuration files: git config [--local|--global|--system] section.key value
.
The name and email that you provide will be used as the committer information for any commit you make. This setting is available at both global and repository scopes, and corresponds to the git config
user.email and user.name settings.
[!INCLUDE temp]
-
In Team Explorer, go to Settings. To set your user name and email at the global level, go to Global Settings; to set these at the repository level, go to Repository Settings.
-
Provide your user name and email, then choose Update to save.
Note that for Repository Settings, you'll first need to check Override global user name and email settings.
To set your user name, open a command prompt, navigate to the repository, and run:
git config user.name "Jamal Hartnett"
By default, this command writes to the local repository configuration file. To write to other files, pass one of the following options: --system
, --global
, or --file <filename>
.
For example, to write to the global configuration file, run:
git config --global user.name "Jamal Hartnett"
Similarly, to set your email, run git config --global user.email "jamal@fabrikam.com"
.
Pruning removes remote-tracking branches that no longer exist on the remote and helps you keep your branches list clean and up to date. This setting is available at both global and repository scopes, and corresponds to the git config
fetch.prune setting.
We recommend setting this option to True at the global level. Valid settings are:
- True (recommended)
- False
- Unset (default)
[!INCLUDE temp]
Requires Visual Studio 2017 Update 5 and later.
In Team Explorer, go to Settings. Go to Global Settings and set Prune remote branches during fetch to True (recommended). Select Update to save.
:::image type="content" source="media/git-config/visual-studio-prune-remote-branches-setting.png" alt-text="Screenshot that shows 'Prune remote branches during fetch' highlighted and with 'True' selected from the drop-down.":::
To prune branches on every fetch
, open a command prompt, and run:
git config --global fetch.prune true
This command will set fetch.prune to true in your global configuration file (recommended).
Rebasing sets aside the changes made by commits in the current branch that are not in the upstream branch, resets the current branch to the upstream branch,
then applies the changes that were set aside. This setting is available at both global and repository scopes, and corresponds to the git config
pull.rebase setting. Valid settings are:
- True: Rebase current branch on top of upstream branch after fetch.
- False: Merge the current branch into the upstream branch.
- Unset (default): Unless specified in other configuration files, merge the current branch into the upstream branch.
- Interactive: Rebase in interactive mode.
- Preserve: Rebase without flattening locally created merge commits.
[!INCLUDE temp]
Requires Visual Studio 2017 Update 5 and later.
-
In Team Explorer, go to Settings. Go to Global Settings to configure this option at the global level; go to Repository Settings to configure this option at the repo level.
-
Set Rebase local branch when pulling to the desired setting, and select Update to save.
:::image type="content" source="media/git-config/visual-studio-rebase-local-branch-setting.png" alt-text="Screenshot that shows 'Rebase local branch when pulling' highlighted and 'True' selected from the drop-down.":::
Note that it is not possible to configure pull.rebase
to Interactive in Visual Studio. Visual Studio does not have interactive rebase support.
To configure pull.rebase
to use interactive mode, use the command line.
To configure pull.rebase, open a command prompt, and run:
git config [--local|--global|--system] pull.rebase [true|false|interactive|preserve]
Cryptographic network provider is a Git configuration setting at global scope that configures which SSL backend to use at runtime, and corresponds to the git config
http.sslBackend setting. The values are:
- OpenSSL: Use OpenSSL for TLS and SSL protocols.
- Secure Channel: Use Secure Channel (schannel) for TLS and SSL protocols. Schannel is the native Windows solution, accessing the Windows Credential Store, thereby allowing for enterprise-wide management of certificates.
- Unset (default): If this setting is unset, OpenSSL is the default.
[!INCLUDE temp]
Requires Visual Studio 2017 Update 7 and later.
-
In Team Explorer, go to Settings. Go to Global Settings to configure this setting.
-
Set Cryptographic network provider to the desired value, and select Update to save.
:::image type="content" source="media/git-config/visual-studio-cryptographic-network-setting.png" alt-text="Screenshot that shows 'Cryptographic network provider' highlighted with 'OpenSSL' selected from the drop-down.":::
To configure http.sslBackend, open a command prompt, and run:
git config --global http.sslBackend [openssl|schannel]
The Ignore & attributes files section is available at repository scope and allows you to view and edit the gitignore and gitattributes files for your repository.
Git will show diffs and merge conflicts in your preferred tools. The settings in this section correspond to the git config
diff.tool and merge.tool settings. You can configure Git to use Visual Studio as your merge or diff tool in Global Settings and Repository Settings by selecting Use Visual Studio. To configure other diff and merge tools, use git config
with the diff.tool or merge.tool switch.
The Remotes section allows you to configure the remotes for this repository. This setting corresponds to the git remote command and is available at the repository scope.
The Other section allows you to view the Git configuration settings for this repository, with the exception of settings that are displayed and managed in the Visual Studio Git settings pane.
To view all of your Git configuration settings, you can open and view the configuration files themselves, or you can run git config --list
to display the settings.
The following settings manage Git-related preferences in Visual Studio, and are managed by Visual Studio instead of Git configuration files. All of the settings in this section are configured on the Global Settings page.
- Default repository location
- Enable download of author images from 3rd party source
- Commit changes after merge by default
- Enable push --force
Default repository location configures the default folder in which repositories are cloned.
Enable download of author images from 3rd party source is a Visual Studio specific setting at global scope. When checked, author images are downloaded from the Gravatar image service, if available, and displayed in the commit and history views.
Important
In order to provide author images in the Commit and History views, the tool creates an MD5 hash for the author email addresses stored in the active repository. This hash is then sent to Gravatar to find a matching hash value for users that have previously signed up for the service. If a match is found, the user image will be retrieved from the service and displayed in Visual Studio. Users that have not configured the service will return a randomly generated image. Note, email addresses are not recorded by Microsoft, nor are they ever shared with Gravatar or any other third party.
When Commit changes after merge by default is enabled, Git automatically creates a new commit when a branch is merged with the current branch.
- When checked,
git merge
commands issued by Visual Studio are run with the--commit
option. - When unchecked,
git merge
commands issued by Visual Studio are run with the--no-commit --no-ff
options.
For more information on these options, see --commit and --no-commit and --no-ff.
Requires Visual Studio 2017 and later.
When enabled, this setting allows you to push --force
from within Visual Studio. By default Enable push --force is disabled.
Warning
Use push --force
with caution as it can overwrite changes that have been pushed to the branch since your last pull. For more information, see push --force.