First of all, you should take care of your data. Make sure you make extra copies of your files, especially the ones that are important to you. For that, you can use your portable hard drive, USB sticks, sd card, etc. Also, you can put your files to cloud or, for example, Dropbox. However, Locky can affect all files that can be reached thru the Internet, so make sure they are disconnected from the Internet. If you want to know more information about Locky, you should read this Locky file recovery guide: http://www.2-spyware.com/remove-locky-file-extension-virus.html
Locky ransomware has been mostly distributed through spam emails with a Word document attachment. When you open the attachment it prompts you to enable a macro. If you do that your data will becomes encrypted and you'll fall victim to the ransomware.
For preventing infection, first of don't open, download attachments you are not 100% sure about. Make sure not to enable any macros unless they are digitally signed (you can adjust your Office settings to prevent this). As always have a backup of your data and update your anti-virus and anti-malware regularly.
Specifically with Locky there are a number of vulnerabilities that have been found, which will allow you to prevent the infection, such as creating a registry key ahead of time, preventing Locky from creating the same key and infecting your machine. This trick an others are covered in an article below. http://www.csoonline.com/article/3047167/security/this-bag-of-tricks-may-help-stop-a-locky-ransomware-infection.html