If you are using the standard Jekyll minima 3 theme hosted on Github pages this can be done fairly easily.

Create a file called custom-head.html under _includes and add the following snippet in:

{% if page.lang %}
<link rel="alternate" hreflang="{{ page.lang }}" href="https://www.yourdomain.com/{{ page.url }}" />
{% else %}
<link rel="alternate" hreflang="x-default" href="https://www.yourdomain.com/{{ page.url }}" />
{% endif %}

Then for posts written in different languages, add a “lang:” attribute in the post front matter, and set that as the target language. Remember you can also set regional localisation too, for example pt-BR for Portuguese speakers in Brazil, but also in cases like es-JP for Spanish speakers in Japan. Google follows ISO639-1 for languages and ISO 3166-1 Alpha 2 for countries.