LoginSignup
0
0

More than 1 year has passed since last update.

.gitignore をサクッと作成してみました

Posted at

概要

Gitを利用するときに、「.gitignore」へ不必要なファイル・ディレクトリを指定することにより、リポジトリの管理対象から除外することができます。その「.gitignore」のサクッとした作成方法となります。

ローカル環境

  • macOS Monterey 12.1
  • zsh 5.8
  • Azure CLI 2.28.0
  • terraform v1.0.11
  • git 2.34.1

GitHub管理の .gitignore テンプレート

  • Githubチーム(?)が管理している .gitignore テンプレートが公開されています。いろいろなプログラミング言語、フレームワーク、エディタ、ツール、OS等を網羅されているように思います。
    • ルートフォルダには、一般的なプログラミング言語とツール等のテンプレート
    • Global には、各種エディター、ツール、およびオペレーティングシステム等のテンプレート
    • community には、現在主流のテンプレートに属していない言語、ツール、環境等のテンプレート

.gitignore の作成方法

この公開されているテンプレート利用して、自分に必要な .gitifnore ファイルを作成します。

## 実行したディレクトリに毎回新規に .gitignore を作成します。
$ curl -sS https://raw.githubusercontent.com/github/gitignore/master/{\
Java.gitignore,\
Terraform.gitignore,\
Python.gitignore,\
Global\/macOS.gitignore,\
Global\/Linux.gitignore,\
Global\/Windows.gitignore\
} > .gitignore
## 実行したディレクトリに存在する .gitignore に追記されます。
## 実行したディレクトリに .gitignore が存在しなければ、新規に作成されます。
$ curl -sS https://raw.githubusercontent.com/github/gitignore/master/{\
C.gitignore,\
C++.gitignore\
} >> .gitignore

.gitignore の運用方法(案)

git init / git clone を実行した(する)ディレクトリで .gitignore を作成するために ~/.zshrc に「function GitIgnore()」を追記しておきます。

function GitIgnore() {
curl -sS https://raw.githubusercontent.com/github/gitignore/master/{\
Java.gitignore,\
Terraform.gitignore,\
Python.gitignore,\
Global\/macOS.gitignore\
} > .gitignore
}

.gitignore を必要とするとき、該当ディレクトリで「GitIgnore」を実行します。

$ GitIgnore
$ ls -l
total 16
drwxr-xr-x  3 ituru  staff    96  1 19 09:47 ./
drwxr-xr-x  4 ituru  staff   128  1 18 14:00 ../
-rw-r--r--  1 ituru  staff  4327  1 19 14:32 .gitignore

まとめ

公開されている .gitignoreテンプレートから必要なテンプレートを指定するだけで、サクッと .gitignore を作成することができます。

参考記事

以下の記事を参考にさせていただきました。感謝申し上げます。
より良い .gitignore を一瞬で手に入れる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0