My .gitignore doesn't work

Problem: files from .gitignore are pushed to github

Steps:

  • created new repo on github from my repl
  • created .gitignore via shell in repl
  • added code_to_ignore.py into .gitignore
  • executed in shell from root
git add .
git comit -m 'some commit'
git push

Expected result: no file code_to_ignore.py
Got result: all the files are on github

appreciate any help

Hey, @amikhailovskaia welcome to the forums!

Can you please provide a link to the repl? This way it is easier for staff and members of the community to help you!

Also see this guide on how to share your code:

Git will still track and include them in the repository. The .gitignore file only affects files that are untracked at the time the file is added to the ignore list

try these commands

git rm --cached code_to_ignore.py
git commit -m "Remove files from Git tracking"
git push

replace “Remove files from Git tracking” with the actual files, well its a commit message so adjust it as you deem helpful

1 Like

https://replit.com/@amikhailovskaia/TestRepl?v=1

It was really helpful,
thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.