Skip to content

Latest commit

 

History

History
109 lines (81 loc) · 3.53 KB

File metadata and controls

109 lines (81 loc) · 3.53 KB

Git Configurations

In Git, the git config command is used to set various configurations that affect how Git behaves. These settings can be global or local, depending on whether you want the configuration to apply across all repositories or just one specific repository.

Git configuration locations

  • System: Applies to all users on the system.

    • File: /etc/gitconfig
    • Command: git config --system
  • Global: Applies to the current user.

    • File: ~/.gitconfig or ~/.config/git/config
    • Command: git config --global
  • Local: Applies to the current repository.

    • File: .git/config
    • Command: git config --local

Important Git Configuration Settings

  1. User Information:

    • user.name: Sets the name Git uses for commits.
    • user.email: Sets the email address Git uses for commits.

    These are crucial settings because they help identify who made each commit.

    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"
  2. Editor:

    • core.editor: Specifies the text editor Git will use for commit messages and other tasks.

    Example to set VS Code as the editor:

    git config --global core.editor "code --wait"
  3. Line Ending Handling:

    • core.autocrlf: Helps in dealing with line endings when working across different operating systems (Windows vs. Unix-based systems).
      • true: Converts line endings to CRLF when checking out code, and back to LF when committing.
      • input: Converts CRLF to LF on commit but not on checkout.
      • false: No automatic conversion.

    Example for Unix-based systems:

    git config --global core.autocrlf input
  4. Default Branch Name:

    • init.defaultBranch: Sets the default branch name when creating a new repository. The default name is master, but this can be changed (e.g., to main).
    git config --global init.defaultBranch main
  5. Merge Tool and Diff Tool:

    • merge.tool: Defines the default tool for resolving merge conflicts.
    • diff.tool: Sets the default tool for showing diffs.

    Example:

    git config --global merge.tool vimdiff
  6. Credential Helper:

    • credential.helper: Helps to manage and cache credentials for repositories.

    Example for caching credentials:

    git config --global credential.helper cache
  7. Color Output:

    • color.ui: Enables colored output for Git commands to make them easier to read.

    Example:

    git config --global color.ui auto

Global vs. Local Settings

  • Global Settings: These settings apply to all repositories for a specific user. They are stored in the ~/.gitconfig file and are generally used for user-specific configurations like username, email, and default editor.

    Example:

    git config --global user.name "Your Name"
  • Local Settings: These settings apply only to a specific Git repository. They are stored in the .git/config file within that repository. Local settings override global settings for that particular repository.

    Example (setting the editor for just one repository):

    git config --local core.editor "nano"

You can check your configurations with the following commands:

  • Global:
    git config --global --list
  • Local (within a repo):
    git config --local --list

To override a global setting with a local one, just run the git config --local command inside the repo.