Changes
Ignoring files and .gitignore templates
8 min read
.gitignore is the file, at the root of the repository, that lists what git should pretend not to
see: build folders, downloaded dependencies, logs, editor files, local secrets such as .env. An
ignored file disappears from the changes panel and isn't included in Stage all changes.
Versora offers two ways: ignore a file from the list right away (the file, its extension or its folder) and add at once a template with the typical patterns of a language, a framework, an editor or an operating system.
Tip
.gitignore is a repository file like any other: after you change it, it appears in Unstaged
files and needs to be committed to apply to the team.
Adds to .gitignore a pattern made from the chosen file. If the file was already tracked by git,
Versora also removes it from git (without deleting it from disk); without that, it would keep
appearing, despite the pattern.
- File menu in Unstaged files › Ignore › (submenu).
The submenu changes depending on the file. For logs/app/servidor.log:
| Item | Pattern added | When it appears |
|---|---|---|
| servidor.log (untracked file) | /logs/app/servidor.log | Always. |
| servidor.log — ignore and stop tracking (already tracked file) | /logs/app/servidor.log | Instead of the previous one, when git already tracks the file. |
| All .log files | *.log | When the name has an extension. |
| Everything in folder logs/app/ | /logs/app/ | When the file is in a folder. |
| .gitignore templates… | (opens the templates window) | Always, after a separator. |
The leading / anchors the pattern to the repository root: /logs/app/ ignores that folder, and
not any logs/app folder somewhere else. The characters .gitignore would treat as wildcards
(*, ?, [, ] and \) in the file or folder name are escaped with \.
- In the changes panel, right-click
logs/app/servidor.log, in the Unstaged files section. - Point to Ignore and choose, for example, All .log files.
- The toolbar shows "Updating .gitignore…" and, at the end, "Added "*.log" to .gitignore" appears.
- The
.logfiles disappear from the list. The.gitignoreappears in Unstaged files: stage it and commit.
- It reads the
.gitignoreat the repository root (or starts an empty one, if it doesn't exist yet). - If the pattern isn't there yet (comparing line by line), it appends it at the end, with the same line ending the file already uses (CRLF or LF).
- On an already tracked file, it removes it from git without deleting it from disk:
echo "*.log" >> .gitignore
git --literal-pathspecs rm -r -q --cached --ignore-unmatch -- logs/app/servidor.log
Ctrl+Z doesn't undo this operation. To go back:
- open the
.gitignore(for example, from its diff, with Edit file) and delete the line; or discard the.gitignorechanges, if it had no others (see Discarding changes); - on a file that stopped being tracked, the removal appears in Staged files as a deletion: unstage it (see Staging) for git to track the file again.
- "ignore and stop tracking" doesn't delete the file from disk, but the next commit records its deletion in the repository. For anyone who pulls that commit, git deletes the file from their working copy. Tell the team before you stop tracking a file other people use (for example, a local configuration).
- With All .log files or Everything in folder logs/app/ on a tracked file, only that
file leaves git. Other already tracked files that match the pattern stay tracked (
.gitignoreonly applies to files git doesn't track yet). - The pattern always goes into the
.gitignoreat the repository root, even if there are other.gitignorefiles in subfolders. - "Invalid ignore pattern.": the pattern ended up empty or with a line break.
- "Couldn't read the .gitignore: …" / "Couldn't write the .gitignore: …": the file is locked by another program or there's no permission.
- The Ignore submenu doesn't appear for conflicted files or for those in the Staged files section.
- The changes panel: the full file menu.
- "Don't commit" list: for a file that should stay tracked, but out of your commits.
- Official git documentation on the format: gitignore (opens another site).
A window with ready-made templates, built into Versora (nothing is downloaded), with the most used
patterns of each language, framework, tool and operating system. You check one or more and see,
before writing, exactly the lines that will go into the file. The ones the .gitignore already has
are left out.
- File menu › Ignore › .gitignore templates…
- Palette (Ctrl+P): ".gitignore templates…" (also found by "gitignore", "ignore" or "template").
- When creating a repository: the .gitignore template (optional) field (next section).
| Group | Templates |
|---|---|
| Languages | Node, Python, Java, Kotlin, .NET / Visual Studio, Rust, Go, C / C++, PHP / Composer, Ruby / Rails, Swift / Xcode |
| Frameworks | Android, Laravel, Dart / Flutter, Unity |
| Tools and editors | Maven, Gradle, Terraform, Visual Studio Code, JetBrains (IntelliJ, Rider…), Vim |
| Operating systems | Windows, macOS, Linux |
Some examples of what each one brings:
| Template | Some of the lines |
|---|---|
| Node | node_modules/, npm-debug.log*, dist/, build/, coverage/, *.tsbuildinfo, .env, .env.local |
| Python | __pycache__/, *.py[cod], .venv/, venv/, .pytest_cache/, .mypy_cache/, htmlcov/, .env |
| .NET / Visual Studio | [Bb]in/, [Oo]bj/, [Dd]ebug/, [Rr]elease/, .vs/, *.user, *.suo, TestResults/, *.nupkg |
| Java | *.class, *.log, *.jar, *.war, *.ear, hs_err_pid* |
| Rust | target/, **/*.rs.bk, *.pdb |
| Go | *.exe, *.dll, *.so, *.test, *.out, go.work, vendor/ |
| Unity | /[Ll]ibrary/, /[Tt]emp/, /[Oo]bj/, /[Bb]uild/, /[Ll]ogs/, *.csproj, *.sln |
| Visual Studio Code | .vscode/*, !.vscode/settings.json, !.vscode/tasks.json, !.vscode/launch.json, *.code-workspace |
| Windows | Thumbs.db, Desktop.ini, $RECYCLE.BIN/, *.lnk, *.stackdump |
| macOS | .DS_Store, .AppleDouble, ._*, .Spotlight-V100, .Trashes |
The full list of each template appears in the window itself, when you check it.
- Open the .gitignore templates window (from the palette, for example).
- Type in Filter templates to find one quickly (for example, "py"). With no result, "No template with that name." appears.
- Check one or more templates: Node and Windows, for example.
- On the right, Lines that will be added shows the exact block, with one comment per template
(
# Node,# Windows). The summary says, for example, "18 new lines (6 already there)". - Click Add to .gitignore (or Create .gitignore, if the repository doesn't have one yet). The toolbar shows "Writing the .gitignore…" and, at the end, "18 lines added to the .gitignore".
- Stage the
.gitignoreand commit.
| Option | What it does | Default |
|---|---|---|
| Filter templates | Shows only the templates whose name contains the text. | Empty |
| Template checkboxes | Mark the templates that go in. The block's order follows the list's order. | None checked |
No git command: the app edits the file.
- It reads the
.gitignoreat the root. - It builds the block: for each checked template, a
# <template name>comment and only the lines that don't exist yet in the file (lines are compared without leading and trailing spaces, ignoring comments) or in a previous template of the same choice. - It appends the block at the end of the file, separated from the previous content by a blank line, with the same line ending the file uses.
- If the file didn't exist, it creates it.
For example, in a .gitignore that already has node_modules/, checking Node adds:
# Node
npm-debug.log*
yarn-debug.log*
...
.env.*.local
- With an already existing
.gitignore: Ctrl+Z restores the previous content ("Undo: Templates in .gitignore (Ctrl+Z)"). - With a new
.gitignore(created by the window): Ctrl+Z doesn't delete it. Nothing is lost: the file appears in the changes, and you can discard it like any new file (see Discarding changes).
- "Nothing to add: the .gitignore already has all 17 lines.": all the lines of the checked templates are already in the file. The button is disabled.
- "Check one or more templates to see what goes in.": nothing checked yet.
- "The .gitignore changed while the window was open. Open it again to see the current version.": another program wrote the file after the window read it. So as not to overwrite it, Versora refuses; close the window and open it again.
- "The .gitignore is too large to edit here.": the file is over 2 MB.
- "Couldn't read the .gitignore: …" / "Couldn't write the .gitignore: …": file locked or no permission.
- Templates only keep new files out of git. Files that are already in the repository (a
node_modulescommitted by mistake, for example) stay tracked; to remove them, use Ignore › "… — ignore and stop tracking" on each one, orgit rm -r --cached <folder>in the terminal. .envis in the Node, Python, PHP / Composer, Laravel and Ruby / Rails templates. To detect secrets that have already been staged, see Checks.- Esc or a click outside the window close it without writing.
When you create a new repository with Versora, you can already choose a template, and the
.gitignore is born together with the repository.
- New repository (init) dialog › .gitignore template (optional). See Open, clone and create repositories.
- Open the New repository (init) dialog.
- Fill in Create in, Folder name and Initial branch.
- In .gitignore template (optional), choose a template from the list (in alphabetical order), for example Python. None (the default) doesn't create the file.
- Click Create repository.
| Option | What it does | Default |
|---|---|---|
| .gitignore template (optional) | Creates the .gitignore with the # <template> comment and the template's lines. Only one template at a time; to combine others, use the .gitignore templates window afterwards. | None |
It writes the .gitignore and, if the repository only has the initial commit the app has just
created (the Create README.md and the initial commit option), includes the file in that commit:
git add -- .gitignore
git commit -q --amend --no-edit --no-verify
Without the initial commit, the .gitignore stays in the changes, waiting for the first commit.
- "The repository already has a .gitignore.": the chosen folder already had a
.gitignore; it isn't replaced. Use the .gitignore templates window to add lines.