Committing build files directly to git repo is not a good practice, but lets see how this could be possible first.
You have two branches in your git repository: main and gh-pages. Two branches are separated so your code committed to main branch would not update the gh-pages branch. To update the gh-pages branch, you need to switch to gh-pages branch to commit your build. But when you switch to gh-pages branch, it would not contain the changes you have committed on main branch because it was branched out from a previous commit, you must rebase first.
So your git workflow would be:
- commit your code to main branch
- rebase gh-pages branch onto main
- switch to gh-pages branch
- build your app, commit your build to gh-pages branch
- force push your gh-pages branch
- switch back to main branch for future commits
Instead of doing above tedious git operations, you should consider using the Deploy to GitHub Pages GitHub Actions. The build and deploy work would be done by the CI/CD systems on cloud, so you don't have to build and commit files locally.