I noticed that if the packages are installed into the Code environment path, the packages will be listed in the "Actually installed packages" section (after clicking the Update button), but these packages will be lost if the environment is rebuilt
So, is there any other way to include these packages into the Code repository?
Indeed you can install packages from github using these methods.
As you noted, since this is a manual operation, this will not be added to the package requirements of the code-env. Hence, these packages will be wiped if you rebuild the code-env from the UI.
To manage installation of custom R packages in a reproducible way, I suggest setting up a local repository, for example using Minicran, and host your custom package releases on this repo. In the code-env custom options you will then be able to point to this local repo.