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:
Step 2: Generate “gitignore” File
Execute the “touch” Git command along with the “~/.gitignore” as a file name:
Step 3: Modify the Global “gitignore” File
To modify the global .gitignore file, run the “start” command to open it with the default editor:
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:
Step 5: Verification
Lastly, verify the newly created file by utilizing the below-stated command:
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.