Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I use git for versioning. Just yesterday I was working on refactoring my Python code base. After adding a test I found that I had introduced a bug in one of project euler solutions. So I checked out a previous version offline, found the diff and went back to latest version and fixed the problem.

It was a bit after that I found a mess up had been done due to this. I use .gitignore to leave many of the unneeded files or WIP things out of git. I found that using checkout and going back to the latest version deleted some files which were not checked in. Now I am finding that a new repo that I keep in an ignored Folder is completed cleaned. It did not have much so far but still all is gone.

So I am confused about what is a good way to keep offline codebase intact in case there are many such folders/files that I do not want to check in? Also how to organize codebase on local for new projects? Just take backups on a drive?

share|improve this question

closed as off-topic by Karl Bielefeldt, gnat, Bart van Ingen Schenau, GlenH7, MichaelT Apr 26 at 15:16

  • This question does not appear to be about software development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

4  
This question appears to be off-topic because it belongs on StackOverflow, but is frequently duplicated there. –  Karl Bielefeldt Apr 25 at 18:46

1 Answer 1

up vote 3 down vote accepted

git does warn you if it is going to modify or delete untracked or uncommitted files. Don't take this lightly.

Do check in everything you work on, all WIP stuff, all temporary stuff. If you can't carelessly delete a file outright, track it. Make a lot of small commits. Once something started to work, commit it; don't mind that it's yet imperfect.

If you care about cleanliness, use separate branches: keep 'master' clean and wildly experiment on feature branches. Branching is incredibly cheap in git. When you want to pull a feature in, use merge or cherry-pick.

If amidst a change you need to check out another commit, git stash is your friend. You can git stash pop on the same or on a different branch; great when you just realized that you had started working on a wrong branch.

And again, look at all your untracked files as useless trash that a janitor may choose to take out at any moment. If something is not trash, git add it.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.