Do I need two GitHub accounts for this?
See the top of the GitHub help page called What's the difference between user and organization accounts?:
Your user account is your identity on GitHub.
Therefore, if you don't want your workplace to be able to identify that you're the author of some personal (i.e. non-work-related) stuff that you've made public, you need to create and use a different GitHub account for that personal stuff.
For instance, use an account called panthro_at_work
for work-related repositories and another account called mystery_man_or_woman
for your personal stuff.
However, also be aware that
One person or legal entity may not maintain more than one free account.
See Account terms and also nulltoken's answer. Therefore, in order to hold two accounts, at least one of them should be a paid account.
Merging accounts
Should you change your mind (at a later stage) about keeping work and personal stuff separate, GitHub allows you to merge your two user accounts; see Merging multiple user accounts.
Transferring repositories between accounts
GitHub allows for even more fine-grained actions than that: you can transfer ownership of only a subset of your repositories in your mystery_man_or_woman
account to your panthro_at_work
account (or vice versa); see How to transfer a repository.
I wish to upload some code that I have written outside of work and make public. Is there a way to mask my username from the public, so work could not see it was me?
Any activity performed against a public repository is also public. For instance, the public activity for the user Octocat can be seen at the following url https://github.com/octocat?tab=activity
Or would I need to create a separate account to upload the code?
I would advise you to take a also take a look at the GitHub Terms of Services which specifically states: "One person or legal entity may not maintain more than one free account."
So, although the system does allow one to create multiple accounts, GitHub legally reserves the right to ban you, at its own discretion:
- "Violation of any of the terms below will result in the termination of your Account."
- "The failure of GitHub to exercise or enforce any right or provision of the Terms of Service shall not constitute a waiver of such right or provision."