使用Gitbash提交项目至GitHub失败,错误指向非目标远程仓库
Hey there, it sounds like your local Git repo is linked to the wrong remote repository, which is why you're hitting that "Repository not found" error for a repo you never intended to push to. Let's walk through how to fix this step by step:
Step 1: Check Current Remote Repositories
First, let's confirm exactly which remote URLs your repo is currently using. Run this command in Git Bash:
git remote -v
This will list all remote repositories tied to your local repo—you’ll probably see that incorrect https://github.com/4bhishekKasam/Authentication-using-Passportjs.gi/ URL listed under the origin remote.
Step 2: Update the Existing Remote URL
If you want to keep using the origin name but switch its URL to your target repository, use this command (replace <correct-repo-url> with your actual repo's HTTPS or SSH URL):
git remote set-url origin <correct-repo-url>
For example, if your correct repo URL is https://github.com/your-username/your-target-repo.git, the command would look like:
git remote set-url origin https://github.com/your-username/your-target-repo.git
Step 3: (Alternative) Delete and Re-add the Remote
If you’d rather start fresh, you can remove the incorrect origin remote entirely, then add the correct one:
- Delete the wrong remote:
git remote remove origin - Add the correct remote (swap
<correct-repo-url>with your actual repo URL):git remote add origin <correct-repo-url>
Step 4: Verify the Change
After making the update, run git remote -v again to double-check that the origin URL now points to your intended repository.
Once that’s sorted, you should be able to run git push -u origin master (or main, if your repo uses that as the default branch) without encountering the repository not found error.
内容的提问来源于stack exchange,提问作者Abhishek Konnur

