How to use global gitignore?

QuestionsQuestions8 SkillsProYour First Git LabOct, 31 2025
0109

To use a global .gitignore file in Git, follow these steps:

Step 1: Create a Global .gitignore File

  1. Open your terminal.

  2. Create a new file for your global .gitignore. You can name it anything you like, but a common name is .gitignore_global. For example:

    touch ~/.gitignore_global

Step 2: Configure Git to Use the Global .gitignore

  1. Set the global .gitignore file in your Git configuration:

    git config --global core.excludesfile ~/.gitignore_global

Step 3: Add Patterns to the Global .gitignore

  1. Open the global .gitignore file in a text editor:

    nano ~/.gitignore_global

    (You can use any text editor you prefer, such as vim, nano, or a graphical editor.)

  2. Add the patterns for files and directories you want to ignore globally. For example:

    # Ignore all log files
    *.log
    
    # Ignore OS-specific files
    .DS_Store
    Thumbs.db
    
    # Ignore IDE-specific files
    .idea/
    *.sublime-workspace
  3. Save and close the file.

Step 4: Verify the Global .gitignore

  1. You can check your Git configuration to ensure the global .gitignore is set up correctly:

    git config --global --get core.excludesfile

    This should return the path to your global .gitignore file.

Step 5: Check Git Status

  1. Now, when you run git status in any repository, Git will ignore the files and patterns specified in your global .gitignore.

Summary

Using a global .gitignore file is a convenient way to ignore files that are common across multiple projects, such as OS-specific files or IDE configurations. This helps keep your repositories clean and focused on the relevant files.

0 Comments

no data
Be the first to share your comment!