I have to preface this talk with: I am not a lawyer. This is intended as peer mentorship, not legal advice.
If you write something good, eventually someone may want to use it. It pays to think ahead a bit and ask yourself what you want them to use it for.
There's this "hacker" ethos that's common in programming. People want to make cool tools and they want others to use them. It's common for people to give away really valuable software – like Flask or Linux or Python for free.
And because such great free software exists, it's hard to get people to pay for a lot of software tools, unless you promise to make their life easier with them.
Everything you post to Github is by default copyright by you. It isn't patented – that's a separate legal process – but you still own the copyright for it and technically, you can sue people if they use it without permission.