At the beginning, I tried to push:
$ git push -u origin main
The result was:
remote: Permission to XXX/repo.git denied to Olduser.
fatal: unable to access 'https://github.com/xxx/repo.git/': The requested URL returned error: 403
Because I had previously set a local username, but it showed that the old user was denied access, I thought the author of the last commit was still the old user, which caused the authentication to fail.
So I tried again:
$ git commit --amend --reset-author
The result was still the same. Finally, I found a solution on stackoverflow.
Just delete this credential, which wasted me 1 hour.