'git push heroku; Please double-check your credentials and correct them

I recently changed my Personal Access Token on GitHub, and I think I've put the new token in all the right places... but maybe I am missing a place?

The problem:

$ git push staging my_cool_branch:master
...
...
...
remote: -----> Installing dependencies using bundler 2.2.33
remote:        Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
remote:        Fetching gem metadata from https://rubygems.org/.......
remote:        Fetching gem metadata from https://rubygems.pkg.github.com/private_org/.
remote:        
remote:        
remote:        Bad username or password for https://[email protected]/private_org/.
remote:        Please double-check your credentials and correct them.
remote:        Bundler Output: Fetching gem metadata from https://rubygems.org/.......
remote:        Fetching gem metadata from https://rubygems.pkg.github.com/private_org/.
remote:        
remote:        
remote:        Bad username or password for https://[email protected]/private_org/.
remote:        Please double-check your credentials and correct them.
remote: 
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
...
...
...

Files (that I am aware of) with Personal Access Token:

$ cat ~/.bundle/config 
---
BUNDLE_RUBYGEMS__PKG__GITHUB__COM: "bart_simpson:ghp_nJabIP9JjPe7KOwgDrkiJextJggm114MZh7f"
BUNDLE_HTTPS://RUBYGEMS__PKG__GITHUB__COM/PRIVATE_ORG/: "bart_simpson:ghp_nJabIP9JjPe7KOwgDrkiJextJggm114MZh7f"

and

$ cat ~/.gem/credentials
---
:github: Bearer ghp_nJabIP9JjPe7KOwgDrkiJextJggm114MZh7f

and

$ cat ~/.gemrc 
---
:backtrace: false
:bulk_threshold: 1000
:sources:
- https://rubygems.org/
- https://bart_simpson:[email protected]/private_org/
:update_sources: true
:verbose: true


Solution 1:[1]

Ah, see ~/.bundle/config above?

The solution was that I also had to set BUNDLE_RUBYGEMS__PKG__GITHUB__COM to the new token in staging:

heroku config:set BUNDLE_RUBYGEMS__PKG__GITHUB__COM=bart_simpson:ghp_nJabIP9JjPe7KOwgDrkiJextJggm114MZh7f

...which, btw, means that you must also set it in .env:

BUNDLE_RUBYGEMS__PKG__GITHUB__COM=bart_simpson:ghp_nJabIP9JjPe7KOwgDrkiJextJggm114MZh7f
BUNDLE_GITHUB__COM=x-access-token:ghp_nJabIP9JjPe7KOwgDrkiJextJggm114MZh7f

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user664833