Git

How to Use a Global .gitignore File?

In Git, a global .gitignore file can help users to avoid committing unnecessary files, maintain consistency across projects, save time, and improve performance. The global .gitignore file is utilized in Git for specifying files and directories that should be ignored by Git across all repositories on a particular user’s system.

This tutorial will demonstrate the usage of a global .gitignore file in Git.

How to Use a Global .gitignore File?

The global .gitignore file is used for specifying the files and directories that should be ignored by Git across all repositories on a particular user’s system. To use a global .gitignore file, check out the below-stated instructions:

  • Navigate to the Git root directory.
  • Create a global .gitignore file by using the “touch” command.
  • Modify its content by executing the “start” command along with the file name.
  • Configure the created file and verify it.

Step 1: View Git Local Directory
First, go to the local Git directory by running the “cd” command:

cd "C:\Users\user\Git"

Step 2: Generate “gitignore” File
Execute the “touch” Git command along with the “~/.gitignore” as a file name:

touch ~/.gitignore

Step 3: Modify the Global “gitignore” File
To modify the global .gitignore file, run the “start” command to open it with the default editor:

start ~/.gitignore

As a result, the file has been opened in the editor. Add desired file name or its extension and save it by pressing the “CTRL + S” keys:

Step 4: Configure the Created File
Now, configure Git for using the newly created “~/.gitignore” file by executing the “git config” command:

git config --global core.excludefile ~/.gitignore

Step 5: Verification
Lastly, verify the newly created file by utilizing the below-stated command:

git config --global core.excludefile

The mentioned output indicates that the file has been created and configured successfully:

That’s all about the usage of the global .gitignore file in Git.

Conclusion

To use a global .gitignore file, first, go to the Git root directory and create a global .gitignore file by using the “touch” command. Then, modify its content by executing the “start” command. Lastly, configure the created file and verify it. This post illustrated the method for using the global .gitignore file in Git.

About the author

Hafsa Javed