0

I'm working on a GitHub repository with other people. The repository is owned by an organization and is private. I wrote a script to help me with some things locally, but I don't want to push it because it's specific to my needs and I don't want to clutter the repository for everyone else. I also don't want to add it to .gitignore for the same reason. However, I would like to ignore it so that it doesn't clutter my git status display (and also so I don't accidentally commit it). I saw this StackOverflow thread that talks about how to do this very thing, so I tried it out. Specifically, it talked about how to use the .git/info/exclude file to ignore files local to this clone of the repo. However, it wasn't working, so I tried to zero in on exactly what the problem was.

To figure out what wasn't working, I tried creating a new clone of the repository:

mkdir test
cd test
git init

Then, I created a dummy file to see what, if anything wasn't working:

touch asdf.txt

When I ran git status, asdf.txt showed up as an untracked file (like I had been expecting). But when I added it to .git/info/exclude:

echo "asdf.txt" >> .git/info/exclude

it no longer showed up in the git status display.

But here's where it gets weird. I then tried pulling from the remote repository:

git remote add origin <url>
git pull origin main

And at this point, asdf.txt once again showed up in the git status display as an untracked file.

I repeated this same process, and the same issue has shown up in another private repository owned by another GitHub organization. However, when I did this with a private repository that I own on my GitHub account, asdf.txt gets ignored like it should. I wouldn't think that this has anything to do with GitHub organizations, though maybe it does. My guess is that it has something to do with the way that the two repositories in question are configured.

Does anyone with expertise in Git know what could cause the .git/info/exclude file to not work? Thanks so much!

S. Brown
  • 401
  • 3
  • 6

1 Answers1

1

git check-ignore -v --no-index asdf.txt will tell you where git found the rule that matched. A !*.txt in the toplevel project .gitignore would do it, see the ignore docs for precedence: work tree .gitignores can only be overridden by command line args.

Since git status says the file's untracked you don't need the --no-index part here, I'm just mentioning it to forestall confusion later.

jthill
  • 55,082
  • 5
  • 77
  • 137
  • The top-level `.gitignore` ignores all files without extensions by ignoring `*` then unignoring `!*.*` and `!*/`. That was the issue. Thanks! – S. Brown Jul 05 '23 at 19:27