[Feature Request] Add local-only mode for `.codegraph/.gitignore`
Summary
Currently, CodeGraph generates .codegraph/.gitignore like this:
*
!.gitignore
This ignores all files inside .codegraph/, but intentionally keeps .codegraph/.gitignore visible to Git.
That behavior makes sense when a project wants to commit this file and share the CodeGraph ignore rule with the whole team. However, in many cases CodeGraph is only used by one developer locally. In that scenario, keeping .codegraph/.gitignore unignored creates an extra untracked file:
.codegraph/.gitignore
As a result, the user has to either commit a CodeGraph-specific file, manually edit the generated .gitignore, or manually add .codegraph/ to the project root .gitignore.
Problem
For users who treat CodeGraph as a local-only indexing/cache tool, the generated .codegraph/.gitignore can be slightly intrusive.
The current generated content:
*
!.gitignore
means .codegraph/.gitignore itself appears in git status unless it is committed.
That creates a few drawbacks:
- It requires an extra commit just to silence
git status. - It adds a
.codegraph/.gitignorefile to the repository, even if other teammates do not use CodeGraph. - For projects where CodeGraph is only used by one developer, the committed
.codegraph/directory can look unexpected or unnecessary. - Users may prefer CodeGraph's database and metadata to remain entirely local, with no repository footprint at all.
Proposal
Could CodeGraph support one of the following options?
Option 1: Generate only * in .codegraph/.gitignore
Instead of generating:
*
!.gitignore
generate:
*
This would cause .codegraph/.gitignore to ignore itself as well, making the entire .codegraph/ directory local-only and invisible to git status.
Option 2: Add an init option
For example:
codegraph init --local-only
or:
codegraph init --ignore-self
When this option is used, CodeGraph could generate:
*
instead of:
*
!.gitignore
The current behavior could remain the default for users who want to commit .codegraph/.gitignore and share the ignore rule with the repository.
Expected behavior
When using the proposed local-only mode:
codegraph init --local-only
CodeGraph would generate this file:
*
Then git status would not show .codegraph/ at all.
Expected result:
.codegraph/ never appears in git status
no extra commit is needed
no CodeGraph-specific file appears in the repository
teammates who do not use CodeGraph are not affected
Current workaround
Users can manually replace:
*
!.gitignore
with:
*
or add this to the project root .gitignore:
.codegraph/
However, it would be nicer if CodeGraph supported this directly during initialization.
Why this would help
The current behavior is useful for projects that want to commit a repository-level CodeGraph ignore rule.
A local-only option would make CodeGraph less intrusive for individual developers who only want a local cache/index and do not want any CodeGraph-specific files to appear in the repository.
+1 - this would really ease things!
codegraph init --local-only is on main now (#3104) and ships in the next release, @jadchene. It makes .codegraph/.gitignore ignore itself, so nothing of CodeGraph's shows in git status, and it works on a project that's already set up without indexing again. A file you've edited or committed is left alone, with a note saying why. Thanks to @jiangyq9 for the first implementation!