PHPackages                             oohology/gitignorewriter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. oohology/gitignorewriter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

oohology/gitignorewriter
========================

Interface for editing .gitignore files in PHP.

v1.1.0(9y ago)040.8k↓42.3%3BSD-3-ClausePHPPHP &gt;=5.6.0

Since Jan 5Pushed 9y ago2 watchersCompare

[ Source](https://github.com/oohology/gitignorewriter)[ Packagist](https://packagist.org/packages/oohology/gitignorewriter)[ RSS](/packages/oohology-gitignorewriter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (3)

GitIgnoreWriter
===============

[](#gitignorewriter)

Interface for editing .gitignore files in PHP

[![Build Status](https://camo.githubusercontent.com/88e1af3609d4f0d398e8ae12bfe57e75c88b5cdf4346fbca276884e345aaf2f6/68747470733a2f2f7472617669732d63692e6f72672f6f6f686f6c6f67792f67697469676e6f72657772697465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/oohology/gitignorewriter)

---

Basic Usage
-----------

[](#basic-usage)

In general, you will open a .gitignore file, use the `add`, `before`, or `after` methods to append, or insert some values, and then call the `save` method to write the result.

Open a file and add a value:

```
use GitIgnoreWriter\GitIgnoreWriter;

$writer = new GitIgnoreWriter('../.gitignore');
$writer->add('.env');
$writer->save();

```

Also supports fluent interface:

```
(new GitIgnoreWriter('../.gitignore'))
    ->add('setup.php')
    ->before('setup.php', 'install.php')
    ->save();

```

Output File
-----------

[](#output-file)

There are multiple ways to read from a source file, make some changes, and write the result to a different output file. The end result is the same, so choose whichever method best fits your use case:

```
$writer = (new GitIgnoreWriter('.gitignore.example'))
	->setOutputPath('.gitignore');
// ...
$writer->save();

```

Or alternately:

```
$writer = (new GitIgnoreWriter('.gitignore.example'));
// ...
$writer->save('.gitignore');

```

Or using the `load()` method:

```
$writer = (new GitIgnoreWriter('.gitignore'))
	->load('.gitignore.example');
// ...
$writer->save();

```

Adding and Inserting Values
---------------------------

[](#adding-and-inserting-values)

The `add` method appends lines starting at the current position in the file, which defaults to the end of the file.

```
$writer->add($value);

```

The `before` and `after` methods first seek the current position to a given line, and then start inserting lines relative to that position

```
$writer->before($find, $prependValue);
$writer->after($find, $appendValue);

```

The `add`, `before` and `after` methods each will accept the values to be inserted in multiple formats:

- a single-line string
- a multi-line string
- an array of strings

More examples:

```
$writer->add('
    # You can write comments
    First/Line/Path

    # blank lines are retained as well
    Second/Line/Path
')->save();

$writer->add([
    'line1',
    'line2',
    'line3',
])->save();

```

Manually seeking
----------------

[](#manually-seeking)

The `rewind`, `seek` and `eof` methods allow you to manually seek the internal pointer to a specific line in the file. Any subsequent `add` will insert content relative to that position.

- `rewind`: set the pointer to the beginning of the file
- `seek`: set the pointer to a specific line number starting at 0
- `eof`: set the pointer to append to the end of the file

Deleting Lines
--------------

[](#deleting-lines)

The `delete` and `deleteOffset` methods provide ways to remove lines from the file. Note that the remaining lines are renumbered after deletion.

- `delete($value)`: remove a matching line from the file
- `deleteOffset($offset, $count = 1)`: delete one or more lines, starting at a specific 0-based line number.

Examples:

```
$writer
    ->delete('working/')
    ->save();

$writer->deleteOffset(5, 2)->save();

```

Test if a line exists
---------------------

[](#test-if-a-line-exists)

The `exists` method returns a boolean to test if a line exists in the file.

`$result = $writer->exists('.env');`

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

3419d ago

PHP version history (2 changes)v1.0.0PHP &gt;=5.4.0

v1.0.1PHP &gt;=5.6.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3557299?v=4)[David Woodmansee](/maintainers/davidwoodmansee)[@davidwoodmansee](https://github.com/davidwoodmansee)

---

Top Contributors

[![davidwoodmansee](https://avatars.githubusercontent.com/u/3557299?v=4)](https://github.com/davidwoodmansee "davidwoodmansee (12 commits)")

---

Tags

phpwritergitignore

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/oohology-gitignorewriter/health.svg)

```
[![Health](https://phpackages.com/badges/oohology-gitignorewriter/health.svg)](https://phpackages.com/packages/oohology-gitignorewriter)
```

###  Alternatives

[suin/php-rss-writer

Yet another simple RSS writer library for PHP 5.4 or later.

2651.4M20](/packages/suin-php-rss-writer)[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
