I use git but I am constantly finding myself in the wrong branch and then when I commit I realize I have done a ton of work in the wrong place.
How do you avoid doing this? Is it just something that comes with time? Or is there some trick you have to avoid this?
i dont use this (see my comment) but i know these things exist: https://github.com/jimeh/git-aware-prompt
i.e: a bash prompt which changes as you change branches to keep you aware of which branch you're on.
A very simple solution, but it works very well. Post-its! Yes, add a post-it somewhere you'll glance over while coding. "Have you checked your git branch?" A more technical solution would be to make it show when opening a terminal or your IDE, maybe change the 'default' file to something that asked you to check. Or use a post-it program. Or, if you're going for a more fun solution, add a speech synthesis program to your login script that says that. There are some code editors/IDE's that integrate with git and show the branch in a status bar.
You can use git branch in prompt like this but this could be only applied, when you are using bash, or you can use Oh My Zsh with git plugin.
Another option could be a pre-commit hook, which runs only once: you can find here an example. This could warn you about the target branch. Pre-commit hooks can also protect the master/production branch, no push without pull-request. With Yelp's framework, you have more options.