In this case, you would make it a Theme Component and add that Component to all Themes. (I’ll admit this is an additional complexity).
If you want to run the site professionally, making sure all your code is on Github is a very good idea indeed.
However, initially when you are just trying some ideas, for sure, you can mess with it “locally” if you so please.
When code changes have settled down, you should probably stick it in source control, but I’d argue the earlier the better.
A way of combining quick evolution with GitHub is to combine it with this:
And deploy to a test Theme Component in a Test Theme … but now we are really getting funky …
Which allows you to deploy on the fly, then you can secure your changes to a git repo once happy.