Skip to content

Instantly share code, notes, and snippets.

@zachshallbetter
Created November 6, 2023 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachshallbetter/846261ac774cf4be7ec5e9c5aea37b72 to your computer and use it in GitHub Desktop.
Save zachshallbetter/846261ac774cf4be7ec5e9c5aea37b72 to your computer and use it in GitHub Desktop.
Github Global .gitignore

On macOS, as with other Unix-like operating systems, global gitignore settings are defined in a global .gitignore file, which Git checks in addition to the project's .gitignore. This is used to ignore files and directories that are specific to your local environment, such as OS-specific files or IDE-specific files, which should not be committed to shared repositories.

Here’s the step-by-step process to set up a global .gitignore file on macOS:

  1. Open the Terminal: You can do this by using Spotlight (Cmd + Space), then typing "Terminal" and hitting Enter.

  2. Choose a location for your global .gitignore: Commonly, this would be in your home directory for easy access.

  3. Create or edit your global .gitignore file:

    • You can use any text editor to create or edit this file. For example, using nano would be nano ~/.gitignore_global.
  4. Add the rules:

    • Each line in the .gitignore_global file specifies a pattern. For example:
      .DS_Store
      .AppleDouble
      .LSOverride
      
    • These lines ignore common macOS system files that you typically don’t want to include in your repositories.
  5. Configure Git to use the global .gitignore file:

    • Run the following command in the terminal to tell Git where your global .gitignore file is:
      git config --global core.excludesfile ~/.gitignore_global
      
  6. Verify the Configuration:

    • To verify that Git is using the right .gitignore_global file, you can use:
      git config --global core.excludesfile
      
    • It should output the path to your global .gitignore.

Remember that the global .gitignore file only affects your local environment. Other collaborators on the project may have different global ignore settings. Project-specific ignore rules should still go into the .gitignore within the project's repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment