Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

Git & GitHub IntroductionChapter 3. Git & GitHub Project Setup

Project Initiator – .gitignore File

Project Initiator – .gitignore File

Understanding the .gitignore File in Git Projects

Files that you don't want Git to track

One of the key values of Git is sharing files. There are files or directories which you may not want to share or you don't need to share. For example, the .env file may contain passwords or other secret information. Suppose you keep the file in your project directory. In that case, Git detects the file and it will be stored in the Remote Repository when you push the project directory into the Remote Repository. If you are a Mac user, you may see a .DS_Store file as a hidden file in each directory. This file is used to store custom attributes of the folder on your computer, such as the position of icons or the choice of a background image. This file is also not necessary for a coding project and doesn’t require sharing with other developers.

The .gitignore file

To exclude those files from the Git version control system, Git uses the .gitignore file. The files and directories written in the .gitignore file are excluded from the Git version control system.

Besides the .env file and OS-specific files, log files and package files are also typically written in the .gitignore file.

Executing this is very simple. You just need to do the following actions.

  1. Create a .gitignore file right under the project directory (the same level as .git directory)
  2. In the .gitignore file, list up files or directories you want to exclude from the Git version control system and save the .gitignore file

To understand the concept more clearly, please go through the practice section below.

Practice

bloovee-round-icon.pngDeveloper A (Project Owner Role)

Objective:
Create a .gitignore file and test it

1. Prepare a test file

Create .env file and run the git status command. The git status command gives you the status of the files that are recognized by the Git system.

Command Line - INPUT
touch .env
git status

You can see that the .env file is recognized by the Git system as shown below. The response says "untracked" but these files are already recognized by the Git version control system. The status tells that those files are not added to the Staging Area, which will be explained in more detail later.

Command Line - RESPONSE
On branch master
No commits yet
Untracked files:
  (use "git add ..." to include in what will be committed)
	.env
nothing added to commit but untracked files present (use "git add" to track)

2. Create and edit the .gitignore file

Create the .gitignore file.

Command Line - INPUT
touch .gitignore

You'll see the .gitignore file in the VS Code.

Creating and editiing the .gitignore file

Open the file and edit it by adding .env. For Mac OS, also add .DS_Store. This file is an auto-generated file by Mac OS to store custom attributes of its containing folder, such as folder view options, icon positions, etc. You don't need to add .DS_Store for Windows.

.gitignore
.env
.DS_Store

Make sure that you save the file.

3. Check that the selected files are ignored

Run the git status command to check the files recognized by the Git system

Command Line - INPUT
git status

You can see that the .env file and .DS_Store file are no longer recognized by the Git system as shown below.

Command Line - RESPONSE
On branch master
No commits yet
Untracked files:
  (use "git add ..." to include in what will be committed)
	.gitignore
nothing added to commit but untracked files present (use "git add" to track)

Delete the .env file as it will not be used in the following sections.

(As the .DS_Store file is an auto-generated file by Mac OS, you don’t need to delete it. Even if you delete it, it will be automatically generated again.)

4. Commit the .gitignore file

As the .gitignore file itself needs to be tracked by Git, add the file to the Staging Area and make a commit by running the command below.

Command Line - INPUT
git add .
git commit -m "added .gitignore file"

You can confirm that the file has been committed.

Command Line - RESPONSE
git commit -m "added .gitignore file"
[master acc4aa4] added .gitignore file
 1 file changed, 2 insertions(+)
 create mode 100644 .gitignore

IdeaTips: .gitignore file useful writing rules

Excluding files with a certain extension: if you want to exclude all the files with a specific extension, you can put "*" right before the extension like *exe.

Excluding files under a certain directory: If you want to exclude all the files under a certain directory, you can put "/" right after the directory name like bin/.

IdeaTips: gitignore.io

Listing all necessary items for the .gitignore file may be time-consuming. You can use gitignore.io to check typical files or directories that should be listed in the .gitignore file for a certain type of project.

For example, if you are creating a Django-based app, type 'Django' and click on the Create button.

gitignore.io

You'll see a list of files or directories like in the example below. Copy the list and paste it into your .gitignore file.

.gitignore file example

You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

How Django Manages HTTP Requests and Responses

How Django Handles HTTP Request and HTTP Response

Managing Processes in Linux

Chapter 8. Linux Process Management

Viewing File Contents with cat Command

cat (Display File Content)

Understanding the .gitignore File in Git Projects

Project Initiator – .gitignore File

Managing Resources Between Local and Remote Servers

Manage Local Computer and Remote Server Simultaneously

How Django Manages HTTP Requests and Responses

How Django Handles HTTP Request and HTTP Response

Managing Processes in Linux

Chapter 8. Linux Process Management

Viewing File Contents with cat Command

cat (Display File Content)

Understanding the .gitignore File in Git Projects

Project Initiator – .gitignore File

Managing Resources Between Local and Remote Servers

Manage Local Computer and Remote Server Simultaneously

Tags:

Repository

Commit

.gitignore

Git & GitHub Introduction
Course Content

Chapter 1. Git & GitHub Overview

What Is Git?

What Is Version Control?

How To Save Versions in Git?

Collaborating on Git & GitHub – Remote Repository

Collaborating on Git & Git Hub – Branch

Git & GitHub Basic Life Cycle

Chapter 2. Git & GitHub Initial Settings

Git & GitHub Initial Settings Overview

Key Tool Preparation (1) – Mac

Key Tool Preparation (2) – Windows

Key Tool Preparation (3) – Linux Remote Server

Git User Settings – git config

Create GitHub Account

GitHub Access Authentication Settings

Generating PAT (Personal Access Token)

GitHub SSH Setup

Chapter 3. Git & GitHub Project Setup

Three Cases in Git & GitHub Project Setup

Git & GitHub Project Setup Overview in Different Cases

Building Remote Collaboration Practice Environment

Project Initiator – Key Steps To Launch Git Project

Project Initiator – Create Local Repository (git init)

Project Initiator – Make the First Commit

Project Initiator – .gitignore File

Project Initiator – Create Remote Repository

Project Initiator – Link Between Remote and Local Repositories (git remote add)

Project Initiator – Upload Local Repository to Remote Repository (git push)

Project Initiator – Grant Remote Repository Access to Project Members

Project Member – Start Project As Collaborator

Project Member – Create Copy of Project Code on Local Computer (git clone)

Non-Member – Start Project With Replica of Existing Repository (Fork)

Fork vs. Clone

Chapter 4. Edit & Commit

Git Regular Workflow – Edit & Commit

Edit and Commit Overview (1)

Add Files to Staging Area – git add

Commit Files – git commit

HEAD and INDEX

Check Status of Working Tree and Staging Area – git status

Check Commit Histories – git log

Check Differences – git diff

Restore Files to Working Tree – git restore

Undo Changes – git reset

Delete Files – git rm

Edit and Commit Overview (2)

Chapter 5. Work With Branches

Git Regular Workflow – Work With Branches

What Is Branch?

Branch Operation Basic Life Cycle

Create Branch and Check Branch Status – Git Branch

Switch Current Branch (1) – Git Checkout

Switch Current Branch (2) – Git Switch

Merge Branches – Git Merge

Fast-Forward Merge

Non-Fast-Forward Merge (No Option)

Non-Fast-Forward Merge (--no-ff Option)

Squash Merge

Rebase Branch – Git Rebase

Managing Conflict

Stash Changes – Git Stash

Chapter 6. Remote Collaboration

Git Regular Workflow – Remote Collaboration

Remote Collaboration Overview

Link With Remote Repository – Git Remote

Upload to Remote Repository – Git Push

Download Remote Repository and Merge to Local Repository – Git Pull

Get Remote Repository Information to Local Repository – Git Fetch

Pull vs. Fetch

Request for Review and Merge – Pull Request

Merge Operation Using GitHub

Chapter 7. Supplemental Topics

Git Key Commands and GitHub Key Features

Git & GitHub Glossary

GitHub Other Features

Chapter 1. Git & GitHub Overview

What Is Git?

What Is Version Control?

How To Save Versions in Git?

Collaborating on Git & GitHub – Remote Repository

Collaborating on Git & Git Hub – Branch

Git & GitHub Basic Life Cycle

Chapter 2. Git & GitHub Initial Settings

Git & GitHub Initial Settings Overview

Key Tool Preparation (1) – Mac

Key Tool Preparation (2) – Windows

Key Tool Preparation (3) – Linux Remote Server

Git User Settings – git config

Create GitHub Account

GitHub Access Authentication Settings

Generating PAT (Personal Access Token)

GitHub SSH Setup

Chapter 3. Git & GitHub Project Setup

Three Cases in Git & GitHub Project Setup

Git & GitHub Project Setup Overview in Different Cases

Building Remote Collaboration Practice Environment

Project Initiator – Key Steps To Launch Git Project

Project Initiator – Create Local Repository (git init)

Project Initiator – Make the First Commit

Project Initiator – .gitignore File

Project Initiator – Create Remote Repository

Project Initiator – Link Between Remote and Local Repositories (git remote add)

Project Initiator – Upload Local Repository to Remote Repository (git push)

Project Initiator – Grant Remote Repository Access to Project Members

Project Member – Start Project As Collaborator

Project Member – Create Copy of Project Code on Local Computer (git clone)

Non-Member – Start Project With Replica of Existing Repository (Fork)

Fork vs. Clone

Chapter 4. Edit & Commit

Git Regular Workflow – Edit & Commit

Edit and Commit Overview (1)

Add Files to Staging Area – git add

Commit Files – git commit

HEAD and INDEX

Check Status of Working Tree and Staging Area – git status

Check Commit Histories – git log

Check Differences – git diff

Restore Files to Working Tree – git restore

Undo Changes – git reset

Delete Files – git rm

Edit and Commit Overview (2)

Chapter 5. Work With Branches

Git Regular Workflow – Work With Branches

What Is Branch?

Branch Operation Basic Life Cycle

Create Branch and Check Branch Status – Git Branch

Switch Current Branch (1) – Git Checkout

Switch Current Branch (2) – Git Switch

Merge Branches – Git Merge

Fast-Forward Merge

Non-Fast-Forward Merge (No Option)

Non-Fast-Forward Merge (--no-ff Option)

Squash Merge

Rebase Branch – Git Rebase

Managing Conflict

Stash Changes – Git Stash

Chapter 6. Remote Collaboration

Git Regular Workflow – Remote Collaboration

Remote Collaboration Overview

Link With Remote Repository – Git Remote

Upload to Remote Repository – Git Push

Download Remote Repository and Merge to Local Repository – Git Pull

Get Remote Repository Information to Local Repository – Git Fetch

Pull vs. Fetch

Request for Review and Merge – Pull Request

Merge Operation Using GitHub

Chapter 7. Supplemental Topics

Git Key Commands and GitHub Key Features

Git & GitHub Glossary

GitHub Other Features