Search code examples
gitgithubversion-controlfile-management

Before Github commit: What's your housekeeping rules for file management?


I just finish my first python project and going to Gitbash upload to Github, only then I found the files are in a mess in the project folders: test.json, test2.csv, try.py... I come up with two ideas:

  1. delete the unnecessary files (the risk is that maybe a file name test.json is actually referred by the main code)
  2. add .gitignore (invest more time on keeping junk files?)

Would you please share your insight: how you manage your dev files? naming, structuring etc. How do you keep the folder clean and efficient for each commit? Thanks the community!


Solution

  • Yes, write a .gitignore and keep it up to date. A programmer's job is to teach the computer to do rote tasks, they're better at it. Avoiding accidentally committing junk is a rote task.

    Without a maintained .gitignore every time you commit you have to check you're committing only the right things. You have to be careful every time, and humans are bad at that. With a maintained .gitignore you, and anyone else who might work on the project, can safely git add ..

    A little discipline will make the job easier. Rather than littering the project root with test and temp files, use a temp directory and ignore that. You can also ignore things like test.*, try.*, and *.tmp.


    That you have a bunch of test and try files suggests your tests are not automated. Automated tests are another way to keep your project clean and avoid having to be careful. When your tests are automated, you don't need to write little throw away test files and programs.