Git无法识别已存在远程仓库及推送失败问题求助
Hey there, let's work through these two Git problems you're hitting—they're common for new users, so don't worry!
1. "Repository Not Found" Error When Pushing to GitHub
Even if you've confirmed the URL is correct, there are a few likely culprits here:
Use a Personal Access Token (PAT) Instead of Password
GitHub stopped accepting account passwords for HTTPS Git operations back in 2021, so your earlier attempt to use USERNAME:PASSWORD@ in the remote URL won't work. Here's how to fix it:
- Go to your GitHub Settings → Developer Settings → Personal access tokens → Generate new token.
- Give it a name, check the
repopermission box (this lets it access your repositories), and click "Generate token". Copy this token immediately—you won't see it again. - Update your remote URL with the PAT:
Then try pushing again withgit remote rm origin git remote add origin https://[MyID]:[YOUR_PAT]@github.com/[MyID]/Sandbox.gitgit push -u origin master.
Clear Stored Windows Credentials
Windows might be caching old or incorrect GitHub credentials. To reset this:
- Open the Windows Credential Manager (search for it in the Start menu).
- Go to "Windows Credentials" and delete any entries related to
github.com. - Run your push command again—Git will prompt you to enter your username and PAT.
Double-Check Case Sensitivity
GitHub treats repository names as case-sensitive, but Windows doesn't. If your remote repo is named sandbox (all lowercase) but your URL uses Sandbox, that'll trigger a "not found" error. Verify the exact name in your GitHub repo settings.
2. GH007: Push Would Publish a Private Email Address
Since you already have your GitHub noreply email, you're almost there! Here's how to resolve this:
Configure Git to Use the Noreply Email
You can set this up either globally (for all your Git repos) or just for the Sandbox repo:
- Global config (applies to every repo on your machine):
git config --global user.email "[8-digit-number]+[MyID]@users.noreply.github.com" # Make sure your username matches your GitHub account git config --global user.name "Your GitHub Username" - Repo-specific config (only affects Sandbox):
Navigate into your Sandbox folder first, then run:git config user.email "[8-digit-number]+[MyID]@users.noreply.github.com" git config user.name "Your GitHub Username"
Fix Existing Commits (Optional)
If your initial commit already used your private email, you can rewrite that commit's email (only do this if no one else has pulled from the remote repo—force-pushing will overwrite remote history):
- In your Sandbox repo, run this command (replace placeholders with your actual info):
git filter-branch --env-filter ' OLD_EMAIL="your-private-email@example.com" CORRECT_NAME="Your GitHub Username" CORRECT_EMAIL="[8-digit-number]+[MyID]@users.noreply.github.com" if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] then export GIT_COMMITTER_NAME="$CORRECT_NAME" export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" fi if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] then export GIT_AUTHOR_NAME="$CORRECT_NAME" export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" fi ' --tag-name-filter cat -- --branches --tags - Push the corrected history with:
git push -f origin master
After setting up the noreply email, any new commits you make won't expose your private email address.
内容的提问来源于stack exchange,提问作者Henry

