This is what I understand:
You have a github page foo.github.io
Your domain example.com is redirected to foo.github.io via an A Record with github-provided IP Address. By this, when using URL example.com, the address bar shows example.com, but data is from foo.github.io. Essentially, example.com & foo.github.io show same page.
Now, github's nature is that it supports both http and https; means if you request http on example.com, it will serve http://example.com, and if you request https, it will serve https://example.com (provided your SSL certificate keys are there in github).
What you are asking is that no matter if http was requested or https, only https should always be served.
if (location.protocol != 'https:')
location.href = 'https:' + window.location.href.substring(window.location.protocol.length);
Note: If you have never setup SSL Private and public keys for example.com in 1&1's system, it means you first need to do that, otherwise when https://example.com will be requested, browsers will show an error. I will add some steps for that when I am back from vacation..