git config

Git config

Description

Description

The git config command is a function that sets configuration variables. It controls git look and operation.

The git config levels and files

The git config levels and files

The git config accepts arguments to specify on which configuration level to operate. When looking for a configuration value, Git prioritizes the following order of configuration levels:

.git/config

How to write a value

How to write a value

Here, the example writes the value “[email protected]” to the configuration name user.email. The global level is used so as to set the value for the current operating system user.

git config --global user.email "[email protected]"

The git config usage

The git config usage

The basic use of git config is creating it with a configuration name that displays the set value at that name. Configuration names consist of a ‘‘section’’ and a ‘‘key’’ separated by a dot.

git config user.email

Here, email is a child property of the user configuration block.

The git config editor - core.editor

The git config editor - core.editor

When your identity is set up, Git uses your system’s default editor, which is Vi or Vim. The git config sets up which editor Git will use. Here is the list of most common editors with git config commands:

EditorConfig Command
Atomgit config –global core.editor “atom –wait”
emacsgit config –global core.editor “emacs”
nanogit config –global core.editor “nano -w”
vimgit config –global core.editor “vim”
Sublime Text (Mac)git config –global core.editor “subl -n -w”
Sublime Text (Win, 32-bit install)git config –global core.editor “‘c:/program files (x86)/sublime text 3/sublimetext.exe’ -w”
Sublime Text (Win, 64-bit install)git config –global core.editor “‘c:/program files/sublime text 3/sublimetext.exe’ -w”
Textmategit config –global core.editor “mate -w”

Merge tools of git config

Merge tools of git config

Git uses one of the merge tools in the case of a merge conflict. Git uses an internal implementation of the Unix diff program, by default. Besides, there are a lot of external third party merge conflict resolutions used instead.

Colored outputs

Git supports colors thus simplifying the process of reading Git output. You can use your colors for customizing the output. For setting color values git config command is used.

color.ui

Git automatically colors most of its output, but there is also a master variable if you want to set another color. For disabling all Git’s colored terminal output you can do the following:

git config --global color.ui false

The default setting of color.ui is auto which applies colors directly to the terminal output. It omits color code output when the output is redirected to a pipe or a file.

You can also set the color.ui value to always. It applies color code output when the output is redirected to files or pipes. This can cause problems as the receiving pipe may not be expecting color-coded input.

Git color values

Besides color.ui, there are also other color settings that can be set to false, auto, or always. They can have a specific color value: normal, black, red, green, yellow, blue, magenta, cyan, white.
Colors can be specified as hexadecimal color codes like #1c87c9 or ANSI 256 color values if the terminal supports it.

Git color configuration settings

类目类目
color.branchSets up the output color of the Git branch command.
color.branch. <slot>Is relevant to Git branch output. <slot> is one of the following:

current branch local branch remote branch upstream branch plain (any other ref)| |color.diff|Gives colors to git diff, git log, and git show output| |color.diff.<slot>|Instructs git on which part of the patch (context, plain, meta, frag, old, new, commit, whitespace) a specific color should be used.| |color.decorate.<slot>|Adjusts the color for git log –decorate output. The supported <slot> values are branch, remote Branch, tag, stash, or HEAD. They are applied to local branches, remote-tracking branches, tags, stashed changes and HEAD, respectively.| |color.grep|Gives color to the output of git grep.| |color.grep.<slot>|It can be applied to git grep. The <slot> variable specifies to which part of the grep output (context, filename, function, line number, match, match Context, match Selected, selected, separator) color should be applied.| |color.interactive|Gives color for interactive prompts and displays (e.g. git add –interactive, git clean –interactive)| |color.interactive.<slot>|Targets an “interactive output”. The available <slot> values are: prompt, header, help, error.| |color.pager|Enables or disables colored output when the pager is in use.| |color.showBranch|Enables or disables color output for the git show branch command.| |color.status|Enables or disables color output for Git status.| |color.status.<slot>|Specifies custom color for defined git status elements. <slot> supports the following values: header, added or updated, changed, untracked, branch, nobranch, unmerged.|

The git config aliases

The git config aliases

Aliases are custom shortcuts specifying which command will expand to longer or combined commands. There is no need for typing commonly used commands with aliases. Git has its own alias system which is mostly used to shorten git commit command. The git config command is used to configure aliases.

git config --global alias.ci commit

Aliases can create super-powerful combinations with other aliases.

git config --global alias.amend ci --amend

In the above-mentioned example, an alias amend composes the ci alias into a new alias that uses –amend

Formatting & whitespace

Formatting & whitespace

Enabled Features by Default
indent-with-non-tab
tab-in-indent
blank-at-eof
indent-with-non-tab
tab-in-indent
trailing-space
cr-at-eol
tabwidth=<n>


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部