> For the complete documentation index, see [llms.txt](https://42-guide.gitbook.io/42-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://42-guide.gitbook.io/42-guide/piscine-life/shell00/gitignore.md).

# gitignore

**Objective:**

The goal of this exercise is to create a shell script that lists all the files ignored by your Git repository. This exercise will help you understand how Git handles ignored files and how to work with the `.gitignore` file.

**Instructions:**

1. **Create a Shell Script Named `git_ignore.sh`:**
   * In the `ex06/` directory, create a file named `git_ignore.sh`.
   * This script should list all the files that are ignored by your Git repository.
2. **Format the Output:**
   * The output should list the ignored files, one per line.
   * Example output:

     ```
     .DS_Store
     myfile.c~
     ```

**Detailed Steps:**

1. **Create the `git_ignore.sh` File:**
   * Open your terminal and navigate to the `ex06/` directory.
   * Create a file named `git_ignore.sh`:

     ```bash
     touch git_ignore.sh
     ```
2. **Write the Script:**
   * Open the `git_ignore.sh` file in a text editor and add the following script:

     ```bash
     #!/bin/sh
     git ls-files --others --ignored --exclude-standard
     ```
   * This script does the following:
     * `git ls-files --others`: Lists files that are not tracked by Git.
     * `--ignored`: Includes files that are ignored by Git.
     * `--exclude-standard`: Uses the standard Git exclude patterns (e.g., `.gitignore`).
3. **Make the File Executable:**
   * After saving the file, make it executable by running:

     ```bash
     chmod +x git_ignore.sh
     ```
4. **Test the Script:**
   * Run the script to see if it produces the expected output:

     ```
     ./git_ignore.sh
     ```

**What You Will Learn:**

* **Git Ignore Mechanism:** You will learn how Git handles ignored files and how the `.gitignore` file works.
* **Listing Ignored Files:** You will understand how to list files that are ignored by Git using the `git ls-files` command.
* **Shell Scripting:** You will gain experience in writing simple shell scripts to automate tasks.

**Useful Resources:**

* [**Git Ignore Documentation**](https://git-scm.com/docs/gitignore)**:** Official documentation for the `.gitignore` file.
* [**Git LS-Files Command**](https://git-scm.com/docs/git-ls-files)**:** Official documentation for the `git ls-files` command.
* [**Shell Scripting Basics**](https://www.shellscript.sh/)**:** A beginner's guide to shell scripting.
* [**Git from the Command Line**](https://www.atlassian.com/git/tutorials/git-bash)**:** A tutorial on using Git from the command line.

**Conclusion:**

This exercise helps you understand how Git handles ignored files and how to list them using the command line. By completing this exercise, you will gain practical experience in using Git commands and writing shell scripts, which are essential skills for any developer working with version control systems.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://42-guide.gitbook.io/42-guide/piscine-life/shell00/gitignore.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
