I don’t want to include .DS_Store in my git management…
What should I do…?
This article is recommended for those who are interested in the above.
In this article, I will explain how to exclude .DS_Store files from Git control in an easy-to-understand manner so that even Git beginners can understand!
If you are a git newbie, have you ever accidentally pushed an unwanted file when using the command line? In this article, I would like to introduce two ways to gitignore from all repositories to avoid accidentally pushing .
If you have any questions, please let me know in the comments.
Contents of this article
This article can be read in 3 minutes.
How to exclude .DS_Store①：Create an ignore file in config/git
How to create a common gitignore for all repositories without modifying .gitconfig.
You can set up a common gitignore for all repositories as follows.
- Create a folder named .config/git in your home directory.
- Create a file named “ignore” in .config/git
- Write .DS_Store into the file.
If you use the console, you can do the following.
$ mkdir -p ~/.config/git
$ echo '.DS_Store' >> ~/.config/git/ignore
This way you can add a global ignore list without modifying .gitconfig.
In case you are interested, this method is also mentioned in the official website. So, this method is more appropriate.
If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.git [–local-branching-on-the-cheap]
How to exclude .DS_Store②：Create .gitignore_global and register it in .gitconfig
There is another way to do this.
Create a file named .gitignore_global in your home directory and add .DS_Store to it as in Pattern 1.
Then, register .gitignore_global in .gitconfig by the following command.
$ git config --global core.excludesfile ~/.gitignore_global
Summary 【Choose the best method】
In this article, I explained how to exclude .DS_Store files from Git control so that even a Git novice can understand!
Please try to choose the best method to exclude .DS_Store.
If you have any other useful methods, please let us know in the comments!
Whew! I’m done!
So, what’s DS_Store…?
If you are interested in blogging with Github Pages, please also see this article “[Github] Blogging with Github Pages [Pros and Cons Explained]” and “[Git] Branch Naming Conventions and Development Efficiency [7 Best Practices]“!