08-Git&GitHUb

Version Control Git (Part1-Part.11) [Git (Part.11)]|Setting “.gitignore” and “.gitignore_global” (setting files not to be managed by Git)

Version Control (Part1-Part.11) [Git] articles are available on Amazon kindle Unlimited (e-book).

howahowablog.com will only be able to read Part.5/10/11.

Version Control (Parts 12-21) [GitHub (Part 1)] articles are available on Amazon kindle Unlimited (e-book).

Only part15/19 will be available on howahowablog.com.

Version Control (Part 21-Part.30) [GitHub (Part 2)] articles are available on Amazon kindle Unlimited (e-book).

Only Part.24/30 will be available on howahowablog.com.

Objectives of Chapter 11

Understand the outline of “.gitignore file” and “.gitignore_global file”.
Understand how to set “.gitignore file” and “.gitignore_global file”.

Overview of “.gitignore” and “.gitignore_global”

Overview of “.gitignore”

Overview of “.gitignore”

The “.gitignore” file is a configuration file for specifying files that are not included in Git’s management. “.gitignore” is placed in a Git Managed Directory.

【English translation of speech bubbles】

“.gitignore “ファイルをGit管理下のフォルダに配置すると、以降、この中に書かれたファイルはGitの管理の対象外となります。
→When a .gitignore file is placed in a Git-Managed directory, files written to it are excluded from Git’s control.

【English translation in illustration】

.gitignore ファイル → .gitignore file

ファイルA→fileA, ファイルB→fileB

ワークツリー(ワーキングツリー) → worktree (working directory)

ステージングエリア → Staging Area

ローカルリポジトリ → local repository

You can specify the file name directly in “.gitignore” or “.gitignore_global”, or you can specify the file by its extension.

There are always files in a project that you don’t want to or don’t need to version control with Git.
By specifying these files in “.gitignore”, you can exclude them from Git management.

Overview of “.gitignore_global”

Overview of “.gitignore_global”

With “.gitignore”, it is possible to exclude specified files from management in a directory under Git management.


However, if you have multiple Git managed directories in your PC, in some cases, it is time-consuming to create and set “.gitignore” in each directory.


In such cases, it is convenient to prepare one common setting and apply it to all directories managed by Git. This is done by “.gitignore_global”.

【English translation of speech bubbles】

「.gitignore_global」ファイルをホームディレクトリに配置すると、以降、Gitが管理しないファイルを共通で適用することができます。
→If you place a “.gitignore_global” file in your home directory, you can apply that setting commonly to each directory managed by Git.

Of the files that you do not want to or should not have Git version control over, those whose content is common to both projects should be put in “.gitignore_global”, and those that are needed individually should be put in “.gitignore”.

There are a variety of files that you may want to exclude from Git management.

For example, there are files that collect and contain settings necessary for framework-based development, and files that are automatically spit out by the OS (“Thumbs.db” on “Windows” and “.DS_Store” on “Mac”).

There are also other files that are automatically generated by editors.

These files should not be managed for security reasons, or because they are not relevant to the project.

Automatic generation service for “.gitignore”

With “.gitignore.io” (https://www.toptal.com/developers/gitignore), you can easily generate the file types and other information to be included in “.gitignore (.gitignore_global)”. In this book, copy and paste the generated contents into “.gitignore_global” and place it in your home directory.


※How to set up “.gitignore” and “.gitignore_global” should be decided for each project. In this book, “.gitignore_global” will be placed, but it does not mean that it is not a good idea to create “.gitignore” every time.

Access “https://www.toptal.com/developers/gitignore.”

If you enter “programming language name”, “framework name”, “editor name”, etc. in the input box, it will automatically output items to be excluded.

In this case, we have created the file by entering “Windows” and “Visual Studio Code”.

The following contents will be displayed in your browser. We will copy and paste this content into “.gitignore_global”.

Create a “.gitignore_global” file and copy and paste the contents of gitignore.io displayed in your browser.

  1. Go to your home directory with “cd” command.
  2. Confirm the current directory by “pwd” command.
  3. Create a “.gitignore_global” file by “touch” command.
  4. Check the hidden files in the home directory with “ls -a”.

You can see “.gitignore_global”.

Open “.gitignore_global” in Visual Studio Code and copy and paste the contents generated by “gitignore.io”.

The following is a “.gitignore_global” file that copied the output of “gitignore.io”.

Overwrite, save and close.

The created “.gitignore_global” file must be activated. Activate it with the following command. For Windows

作成した「.gitignore_global」は有効化する必要があります。次のコマンドで有効化します。

For Windows
git config ーーglobal core.excludesfile “%USERPROFILE%\.gitignore_global”

For Mac
git config ーーglobal core.excludesfile ‘~/.gitignore_global’

How to set “.gitignore”

For “.gitignore” also, create a file with the “touch” command and write the necessary contents. You can also create the file using Visual Studio Code or Explorer.

As with “.gitignore_global”, you can also paste the content automatically generated by “gitignore.io”.

※In this section, only “sample.txt” is described in the “.gitignore” file, and we will confirm that this file is excluded from Git’s control.

First of all, We will create “sample.txt” using the “touch” command, and later, append this file name to “.gitignore” to exclude it from Git’s control.

We leave the file unstaged

Create a “.gitignore” file.

Open “.gitignore” and edit it.  Add “sample.txt” to the “.gitignore” file.

Save and close the “.gitignore” file. Check the status of files using the “git status” command. You can see that “sample.txt” is not listed in “Untracked files”.

Since we did not complete the commit in the previous section regarding the addition of the image file, we will commit it before we stage the “.gitignore” file.

The commit message is as follows

Add: 画像ファイルの追加

howahowaSiteのトップページで利用するサンプル画像を追加しています。画像については今後デザイナーから送られたものに変更していきます。

【English translation of messages】

Add: Addition of image files

Sample images for use on the top page of howahowaSite have been added. The images will be changed to the ones sent by the designer in the future.

【Screen capture of the commit message】

続けて「.gitignore」ファイルをステージングしてコミットします。

Staging and committing the “.gitignore” file.

Add: .gitignoreファイルの追加

.gitignoreファイルの追加をしています。

【English translation of messages】

Add: Adding a “.gitignore” file

“.gitignore” file is added.

【Screen capture of the commit message】

That’s all for this article. In the next article, we will explain how to register a GitHub account.

「Git・GitHub」おすすめ書籍6選+α【初心者用4冊&実践用2冊&番外編1冊】| 現役エンジニア&プログラミングスクール講師「Git・GitHub」初心者の方がGitの操作を理解するためのお勧めの書籍について取り上げています。また中級者の方が更に進んだ学習ができる実践的な書籍についてお勧めできる2冊を取り上げています。ページの下部には「おすすめのITスクール情報」「おすすめ求人サイト」について情報を掲載中。...

ブックマークのすすめ

「ほわほわぶろぐ」を常に検索するのが面倒だという方はブックマークをお勧めします。ブックマークの設定は別記事にて掲載しています。

「お気に入り」の登録・削除方法【Google Chrome / Microsoft Edge】| 現役エンジニア&プログラミングスクール講師「お気に入り」の登録・削除方法【Google Chrome / Microsoft Edge】について解説している記事です。削除方法も掲載しています。...
【パソコン選び】失敗しないための重要ポイント | 現役エンジニア&プログラミングスクール講師【パソコン選び】失敗しないための重要ポイントについての記事です。パソコンのタイプと購入時に検討すべき点・家電量販店で見かけるCPUの見方・購入者が必要とするメモリ容量・HDDとSSDについて・ディスプレイの種類・バッテリーの持ち時間や保証・Officeソフト・ウィルス対策ソフトについて書いています。...
RELATED POST
08-Git&GitHUb

バージョン管理【Git と GitHub】まとめ|現役エンジニア&プログラミングスクール講師

2023年6月5日
プログラミング学習 おすすめ書籍情報発信 パソコン初心者 エンジニア希望者 新人エンジニア IT業界への就職・転職希望者 サポートサイト Programming learning Recommended schools Recommended books Information dissemination Computer beginners Prospective engineers New engineers Prospective job seekers in the IT industry Support site
08-Git&GitHUb

バージョン管理(Part.22~Part.30)【GitHub(part.30)】|これまでの流れを確認してサンプルサイトを完成させる(3)| 現役エンジニア&プログラミングスクール講師

2024年1月31日
プログラミング学習 おすすめ書籍情報発信 パソコン初心者 エンジニア希望者 新人エンジニア IT業界への就職・転職希望者 サポートサイト Programming learning Recommended schools Recommended books Information dissemination Computer beginners Prospective engineers New engineers Prospective job seekers in the IT industry Support site
08-Git&GitHUb

Version Control Git (Part.22~Part.30)[GitHub(Part.24)]|Pull requests (re-requests)

2024年5月23日
プログラミング学習 おすすめ書籍情報発信 パソコン初心者 エンジニア希望者 新人エンジニア IT業界への就職・転職希望者 サポートサイト Programming learning Recommended schools Recommended books Information dissemination Computer beginners Prospective engineers New engineers Prospective job seekers in the IT industry Support site
08-Git&GitHUb

Version Control Git (Part.12~Part.21)[GitHub(Part.19)]|How Branches Operate in Collaborative Editing

2024年4月13日
プログラミング学習 おすすめ書籍情報発信 パソコン初心者 エンジニア希望者 新人エンジニア IT業界への就職・転職希望者 サポートサイト Programming learning Recommended schools Recommended books Information dissemination Computer beginners Prospective engineers New engineers Prospective job seekers in the IT industry Support site
08-Git&GitHUb

バージョン管理(Part1~Part.11)【Git編(Part.11)】|「.gitignore」「.gitignore_global」の設定(Gitに管理させないファイルの設定)| 現役エンジニア&プログラミングスクール講師

2024年1月30日
プログラミング学習 おすすめ書籍情報発信 パソコン初心者 エンジニア希望者 新人エンジニア IT業界への就職・転職希望者 サポートサイト Programming learning Recommended schools Recommended books Information dissemination Computer beginners Prospective engineers New engineers Prospective job seekers in the IT industry Support site
08-Git&GitHUb

バージョン管理(Part1~Part.11)【Git編(Part.5)】| 「Gitが管理するフォルダ」と「3つエリア」の概要 | 現役エンジニア&プログラミングスクール講師

2024年1月30日
プログラミング学習 おすすめ書籍情報発信 パソコン初心者 エンジニア希望者 新人エンジニア IT業界への就職・転職希望者 サポートサイト Programming learning Recommended schools Recommended books Information dissemination Computer beginners Prospective engineers New engineers Prospective job seekers in the IT industry Support site