How to cite my own code in an academic paper?
As you suggested you can create a GitHub repository for your code. There is also the possibility to create a release of your repository. Then you can get a DOI for that release using Zenodo:

Zenodo How-to

You can then put that DOI in your paper as reference and do not have the problem with changing code, because the DOI is associated with the specific release.