简体   繁体   English

git 推送错误:即使添加了远程 url 也找不到存储库

[英]git push error: repository not found even though remote url is added

I have added repository url using git remote add origin https://github.com/**.git If I check with git remote -v I can able to see repo url, but still when pushing to same url,using git push origin master I found that remote: Repository not found. fatal: repository 'https://github.com/**.git/' not found I have added repository url using git remote add origin https://github.com/**.git If I check with git remote -v I can able to see repo url, but still when pushing to same url,using git push origin master我发现remote: Repository not found. fatal: repository 'https://github.com/**.git/' not found remote: Repository not found. fatal: repository 'https://github.com/**.git/' not found . remote: Repository not found. fatal: repository 'https://github.com/**.git/' not found Above repository url still alive and I can able to clone but when pushing I stuck with this error What could may be the reason?上面的存储库 url 仍然存在,我可以克隆但是在推送时我遇到了这个错误可能是什么原因?

I have removed .git using rm -rf.git and again initilized the same using git init and i'm able to push the code.我已经使用rm -rf.git删除.git并再次使用git init进行了初始化,并且我能够推送代码。

Follow these steps to avoid the issues.请按照以下步骤避免这些问题。

Adding a project to GitHub without GitHub CLI.在没有 GitHub CLI 的情况下将项目添加到 GitHub。

Create a new repository on GitHub.com.在 GitHub.com 上创建一个新的存储库。 To avoid errors, do not initialize the new repository with README, license, or ignore files.为避免错误,请勿使用 README、许可证或忽略文件来初始化新存储库。 You can add these files after your project has been pushed to GitHub.您可以在您的项目推送到 GitHub 后添加这些文件。

Create New Repository drop-down.创建新存储库下拉列表。 Open Git Bash. Change the current working directory to your local project.打开 Git Bash 将当前工作目录更改为本地项目。

Initialize the local directory as a Git repository.将本地目录初始化为 Git 存储库。

$ git init -b main

Add the files in your new local repository.将文件添加到新的本地存储库中。 This stages them for the first commit.这会将它们分阶段进行第一次提交。

$ git add .
# Adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.

Commit the files that you've staged in your local repository.提交您在本地存储库中暂存的文件。

$ git commit -m "First commit"
# Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.

At the top of your repository on GitHub.com's Quick Setup page, click to copy the remote repository URL. Copy remote repository URL field In the Command prompt, add the URL for the remote repository where your local repository will be pushed.在 GitHub.com 的“快速设置”页面上的存储库顶部,单击以复制远程存储库 URL。复制远程存储库 URL 字段在命令提示符下,添加 URL 作为将推送本地存储库的远程存储库。

$ git remote add origin  <REMOTE_URL> 
# Sets the new remote
$ git remote -v
# Verifies the new remote URL
Push the changes in your local repository to GitHub.com.
$ git push origin main
# Pushes the changes in your local repository up to the remote repository you specified as the origin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM