【Git】How to gitignore .DS_Store in all repositories

エンジニア|ポートフォリオ
New Employee

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 .

エンジニア|ポートフォリオ
New Employee

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.

  1. Create a folder named .config/git in your home directory.
  2. Create a file named “ignore” in .config/git
  3. 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!

エンジニア|ポートフォリオ
New Employee

Whew! I’m done!

So, what’s DS_Store…?

エンジニア|ポートフォリオ
Experienced employee

Oh no…

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]“!

参考

この記事を書いた人

竹田奈央

石川県出身 / 都内在住 / 国立大中退→情報工学科卒 / フリーランスの女性WEBエンジニア / フルリモート / アラサー / 独身 / #ADDress ワーケーション / 松本人志・千鳥好き/ 下記Twitter OR LinkedInボタンで繋がってくれると嬉しいです