AndroidStudio 新規プロジェクトテンプレートから考える .gitignore

標準的な Android アプリ開発環境である AndroidStudio デフォルトのテンプレートは王道。

そのタイミングでの標準的なテンプレートです。

 

■ AndroidStudio プロジェクトデフォルト

今現在、公開されているプロジェクトテンプレートから確認してみます。

Empty Activity を選択しました。

AndroidStudio 新規プロジェクトテンプレートから考える .gitignore

👉 benigumocom/EmptyActivity-2023-02-09: androidstudio default template hatena-bookmark

プロジェクトルートから .gitignore を探ります。



これからスタートするのがいいでしょう。

 

■ A collection of .gitignore templates - github/gitignore

A collection of .gitignore templates

This is GitHub’s collection of .gitignore file templates. We use this list to populate the .gitignore template choosers available in the GitHub.com interface when creating new repositories and files.

👉 github/gitignore: A collection of useful .gitignore templates hatena-bookmark

GitHub 公式のリポジトリから公開されています。

Android アプリ開発に必要そうなものを挙げていきます。


👉 gitignore/JetBrains.gitignore at main · github/gitignore hatena-bookmark


👉 gitignore/macOS.gitignore at main · github/gitignore hatena-bookmark


👉 gitignore/Android.gitignore at main · github/gitignore hatena-bookmark


👉 gitignore/Gradle.gitignore at main · github/gitignore hatena-bookmark

Kotlin.gitignore は、以下 Java.gitignore のエイリアス。

👉 gitignore/Java.gitignore at main · github/gitignore hatena-bookmark

 

■ gitignore.io - toptal/gitignore


👉 gitignore.io - Create Useful .gitignore Files For Your Project hatena-bookmark で利用されている .gitignore リソースは以下で公開されています。

👉 gitignore/templates at master · toptal/gitignore hatena-bookmark

基本的には、先に紹介した github/gitignore と同じものですが、こちら側のみで公開している .gitignore があります。

なので、それらを貼っておきます。


👉 AndroidStudio.gitignore hatena-bookmark


👉 gitignore/Groovy.gitignore at master · toptal/gitignore hatena-bookmark


👉 gitignore/Firebase.gitignore at master · toptal/gitignore hatena-bookmark

 

■ まとめ

以上を参考にすれば、ほぼ書けるはずです。

AndroidStudio 新規プロジェクト作成時に書き出される .gitignore が必要最小限な洗練されてる記述に思えます。

あとは、不要なファイル公開を避ける記述を追加していく、という流れ。

git 全体としては、広く深く記述もいろいろなのでよく使うとこから身につけていく方がいいと思います。

👉 【これだけで大丈夫】.gitignore チートシート - A Memorandum hatena-bookmark

.gitignore 概念の説明や操作としては、GitHub 公式 Doc が最も分かりやすくまとまっています。

👉 ファイルを無視する - GitHub Docs hatena-bookmark
👉 What makes a good template? - github/gitignore: A collection of useful .gitignore templates hatena-bookmark