The config command is used to config the Git.
Scope
The configuration of Git has three scopes.
- system : /etc/gitconfig
- global : ~/.gitconfig
- local : <project root path>/.git/config
Usually, the configurations to be applied commonly to all projects are placed in global, and the configurations to be applied per project are placed in local.
The priority is local > global > system.
Usage
$ git config --system <key> <value>
$ git config --global <key> <value>
$ git config --local <key> <value>
Add --system, --global, or --local option, the configuration is applied to each scope.
$ git config --list [scope]
$ git config -l [scope]
Add --list option to show what is set.
$ git config --edit [scope]
$ git config -e [scope]
Add --edit option to open an editor to modify the configurations.
$ git config --unset [scope] <key>
$ git config --unset-all [scope] <key>
Add --unset option to remove the line matching the key from config file.
Add --unset-all option to remove all lines matching the key from config file.
Configurations
- user.name <user name>
- Set the username
- user.email <email>
- Set the email
- color.ui <*auto | always | true | false>
- Set the color
- Individual configuration is also possible, as follows:
- color.branch
- color.diff
- color.interactive
- color.status
- commit.template <file>
- Git use the given file as the default initial message when you commit.
- core.autocrlf <input | true | false>
- Windows uses both a carriage-return character and a linefeed character for newlines.
- Mac and Linux use only the linefeed character.
- This configuration automatically adjusts this difference.
- On Windows, you should set the true.
- On Mac or Linux, you should set the input.
- core.editor <editor name>
- Set which editor to use when creating or editing commit or tag messages.
- help.autocorrect <time>
- After waiting for the given time, the Git corrects the wrong command itself.
- The time unit is 1/10 seconds. i.e., if you give 10, it means 1 second.
- pull.ff <false | only>
- By default, Git does not create an extra merge commit when merging a commit that is a descendant of the current commit. Instead, the tip of the current branch is fast-forwarded.
- When set to false, this variable tells Git to create an extra merge commit in such a case. (--no-ff)
- When set to only, only such fast-forward merges are allowed. (--ff-only)
- This setting overrides merge.ff when pulling.
- pull.rebase <*false | true>
- When true, rebase branches on top of the fetched branch, instead of merging the default branch from the default remote when "git pull" is run.
Aliasing
You can give an alias to Git commands.
These are some examples.
$ git config --global alias.st status
$ git config --global alias.unstage 'reset HEAD --'
$ git config --global alias.last 'log -1 HEAD'
You can use these like this.
$ git st
$ git unstage
$ git last
I personally prefer using aliases in shell profiles to this. Because I don't even have to type git.
For example, I use 'gst' as an alias for 'git status'.
'DevTools > Git' 카테고리의 다른 글
[Git] Tip: Revert Merged Commit (0) | 2021.03.05 |
---|---|
[Git] Tip: Change committer and author from already committed commit (0) | 2021.02.15 |
[Git] Restore Command (0) | 2020.10.23 |
[Git] Switch Command (0) | 2020.10.23 |
[Git] Getting Started (0) | 2020.09.23 |
댓글