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

参考


この記事を書いた人

竹田奈央

フリーランス女性エンジニア|年収630万円UP&フルリモートで自由な働き方を実現中

石川県出身・東京都在住。国立大学中退後、情報工学科を卒業し、開発歴5年以上。現在はフルリモートで活動するフリーランス女性エンジニアです。

受託開発・SES・自社サービス・上場企業での大規模開発などの開発経験を持ち、柔軟な対応力が強み。アラサーで独立し、単価80万円以上の案件を獲得、年収は630万円以上アップしました。

「地方出身でも」「女性でも」「会社を辞めても」エンジニアとしてキャリアアップできると身をもって実感中。自由な働き方やキャリア形成に興味がある方は、ぜひTwitterまたはLinkedInでお気軽に繋がってください!