If I have put my code in one of the online repositories and have made it public but haven't licensed it... (to which the policy is that you retain the copyright). Is it enough to just commit a licence text file along with the license header in every source file, in order to license the project? Or do I have to create a new project which has those from the very beginning, in which case what should I do with the old one?
Can I license a project which I have already released without a license?
relicensing;unlicensed code
As long as you are the only contributor to a codebase, you can switch the license as you like. So yes, you can change the license, as long as you didn't use code of others. Check the answers to this question about relicensing, if you want to know under which circumstances you can change the license. Basically the same applies here, as you practically you change from an implicit copyright (license without giving any permissions) to an explicit license.