Git and Visual Studio 2017 part 11 : Configuration

In previous article, I explained GitHub and Visual Studio integration to share your work with others. In this article, I look into configuration in Git. If you want to tweak the git behaviors, you can use configuration feature to override the default.

Configuration Scope

Git has three scopes for configuration. System, global and local. Narrower scope overrides the value from wider scope. Simply put, local wins all the time.

System: Applied to all users in your computer.
Global: Applied to you only, but all repositories.
Local: Applied to the repository only.

If you don’t specify scope to ‘git config’ command, git takes –local as default option.

Look at this official page for more detail. I will yet explain most important configurations.

Configuration in Git

Use config command to get or set the values for each options.

1. Run ‘git config -l’ to list all current configuration values. It lists combined results from all scopes.

image

2. Run ‘git config –local -l’ to show configuration set in local scope.

image

3. Run ‘git config user.name’ to show username configuration.

image

4. Run ‘git config user.name <yourname>’ to set the name. Which scope did this value set in? As I omit the scope, it went to local scope. If you want to set this globally, run ‘git config –global user.name <yourname>’ instead. This user.name and user.email are very important when you use GitHub, as it takes these settings to identify the author.

image

My favorite configurations

Slightly off topic, but these are my favorite ones.

core.pager: This decides how paging should work when you have many data, such as log. I prefer to set this to blank (less by default) so that I can see them all at once.
core.autocrlf: Set the line-ending. Windows uses CLRF, thus set it to “true”, which automatically convert LF to CRLF. See official doc for more detail.
alias.<alias>: This is useful to create shortcut of your own. As you can see above, I usually set “lol” for my log options, as I don’t want to keep typing –oneline –graph –all.
help.autocorrect: By enabling this, Git will issue the command even if you mistyped it. But what if Git assumed it wrong? By giving number (1 means 0.1 seconds), Git will wait before issuing the command. You can cancel the command.
color.status: Don’t you think “Red” is hard to see sometime? You can use color configuration to change it. I keep it default for blogging on purpose though. For example, if you run ‘git config color.status.changed yellow’ and ‘git config color.status.untracked magenta’, then it looks like this. You can tweak font style as well Smile

image

Configuration in VS

Before looking into Git configuration in Visual Studio 2017, let me show you important VS related configuration Run ‘git config –global -l’ to list global scope settings. You see merge and diff tools are set to use Visual Studio. Without this, when you run mergetool or diff, Visual Studio won’t launch.

image

Okay, now let’s see Visual Studio 2017 Git configuration.

1. Go to Team Explorer and click Settings. Global Settings is for global scope, and Repository Settings is for local scope. Click “Global Settings”.

image

2. Some values directly goes to Git configuration, such as “User Name”, “Email Address”. But others are Visual Studio settings for Git, such as “Default Repository Location” which is used when you clone repo or Visual Studio checks this place to local repositories. In past article, I explained what “Commit changes after merge by default” does. Yes it is for fast-forward merge. Another interesting setting is “Diff & Merge Tools”. If you lost merge.tool or diff.tool settings by some reason, maybe by re-installing Git tools, come back to this area to reset your default diff and merge tools to Visual Studio. For other settings, click “Learn more” links which gives you the idea.

image

3. Go back and click “Repository Settings”. There are exactly same settings to override global scope, but others are unique to local repository, such as Ignore & Attributes Files. Click “Edit” link for Ignore File.

image

4. You can edit .gitignore in VS editor. You can also study which files or directories are ignored by default.

5. In Repository Settings pane, expand Other section, and you see so many settings. It’s read-only settings but interesting to study.

Summary

Configuration is small, yet important part. So check your settings. It may be also important to use same settings for some configurations through out the team if they work on same repository to match the same behavior. I will cover “diff” in next article. Go to next article.

Ken