[Git] Error: remote rejected (permission denied)

The error pop up When I pushed the changes on a new branch for the first time.

 ! [remote rejected]     oscar-next -> oscar-next (permission denied)
error: failed to push some refs to 'https://github.com/oscarzhou/portainer.git'

The solution is to update the git config like below

git config --local --list
# old config
remote.origin.url=https://github.com/oscarzhou/bar.git
# update new config with
git config remote.origin.url https://foo%40gmail.com@github.com/oscarzhou/bar.git

After that, we can run git push --set-upstream origin <branch_name>


If this post helped you to solve a problem or provided you with new insights, please upvote it and share your experience in the comments below. Your comments can help others who may be facing similar challenges. Thank you!
Buy Me A Coffee
DigitalOcean Referral Badge
Sign up to get $200, 60-day account credit !