Git config

Git config

Git Config: Configure Git Settings

What is git config?

The git config command is used to configure Git settings, such as your username, email, default editor, and aliases. These settings help Git identify you and manage repository behavior.

Types of Git Configuration Levels

Git settings are stored in configuration files at different levels:

LevelScopeCommand
SystemThis applies to all users on the systemgit config --system
GlobalApplies to a specific user (across all repositories)git config --global
LocalApplies only to a particular repositorygit config --local

By default, Git reads settings from all levels, but local settings override global settings, and global settings override system settings.

Basic Git Config Commands

1. Set Username and Email (Required for Commits)

Every commit you make will be associated with this name and email.

git config --global user.name "Your Name" git config --global user.email "your.email@example.com"

To verify:

git config --global --list

2. Change the Default Text Editor

By default, Git uses Vim. You can change it to another editor:

  • VS Code
    git config --global core.editor "code --wait"
  • Nano
    git config --global core.editor "nano"
  • Sublime Text
    git config --global core.editor "subl -n -w"
  • Vim
    git config --global core.editor "vim"

3. Enable Colored Output

Make Git outputs more readable with colors:

git config --global color.ui auto

4. Set Up Aliases (Shortcuts for Commands)

You can create custom shortcuts for frequently used Git commands:

git config --global alias.st status # `git st` instead of `git status` git config --global alias.co checkout # `git co` instead of `git checkout` git config --global alias.br branch # `git br` instead of `git branch` git config --global alias.cm "commit -m" # `git cm "message"` instead of `git commit -m "message"`

To check aliases:

git config --global --list | grep alias

5. Set the Default Branch Name

New Git versions use main instead of master as the default branch:

git config --global init.defaultBranch main

6. Configure Git to Store Credentials (Avoid Login Prompts)

If you frequently push to remote repositories and want to avoid entering your username and password every time:

git config --global credential.helper store

This will save credentials in a plain text file (not recommended for sensitive accounts).

For macOS, use:

git config --global credential.helper osxkeychain

7. View Git Configuration

To see all your Git settings:

git config --list

To check a specific setting, such as the username:

git config user.name

8. Remove a Git Config Setting

To delete a setting, use:

git config --global --unset user.email

To remove all global settings:

rm ~/.gitconfig

Conclusion

The git config command allows you to customize Git behavior, making it easier to use and personalize. Whether setting up your identity, defining aliases, or changing the editor, these configurations enhance your Git experience.

Would you like more details or examples? 🚀

Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
close