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
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.
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”.
Create a “.gitignore_global” file and copy and paste the contents of gitignore.io displayed in your browser.
- Go to your home directory with “cd” command.
- Confirm the current directory by “pwd” command.
- Create a “.gitignore_global” file by “touch” command.
- 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”.
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.
ブックマークのすすめ
「ほわほわぶろぐ」を常に検索するのが面倒だという方はブックマークをお勧めします。ブックマークの設定は別記事にて掲載しています。