I can't get token file to be ignored by git #146999
Replies: 2 comments 2 replies
-
Welcome to the GitHub Community, @hooded-person, we're happy you're here! You are more likely to get a useful response if you are posting your question(s) in the applicable category. I've gone ahead and moved it for you. Good luck! |
Beta Was this translation helpful? Give feedback.
-
The issue is that the file tokens/webhook.token is already part of your Git history because it was included in your first commit. Even after removing it with git rm --cached, Git still “remembers” it as part of the repository history. .gitignore can only prevent untracked files from being added to Git, so it won’t work for files already tracked in your repository. To Stop Tracking and Ignore the File do this:
This command removes the file from the staging area but leaves it intact in your local working directory.
At this point, tokens/webhook.token will no longer be tracked in future commits, and .gitignore will prevent it from being added again. If you want to completely remove the file from the repository history (e.g., for security reasons like removing sensitive tokens), you need to rewrite the Git history. Warning: Rewriting history can cause problems. To rewrite history do:
(If git filter-repo is not available, install it first or use git filter-branch or BFG Repo-Cleaner.)
After this, the file will be removed from the entire repository history. |
Beta Was this translation helpful? Give feedback.
-
Not sure if this is the right place too ask but I accidentally added my token file(
tokens/webhook.token
) to my first git commit and now i can't get.gitignore
to ignore it. I have triedgit rm --cached tokens/webhook.token
but it keeps wanting too retrack the file when i then update the webhook token. How do i fix this?My
.gitignore
:the github repo: https://github.com/hooded-person/KGinfractions
Beta Was this translation helpful? Give feedback.
All reactions