如何解决 git: fatal: No configured push destination
问题:
你已使用以下命令在文件夹中初始化了 git 仓库
git_init.sh
git init现在你已进行了一些提交,你想使用
git_push_attempt.sh
git push但你收到以下错误消息:
git_error_no_push_destination.txt
fatal: No configured push destination.
要么从命令行指定 URL,要么使用以下命令配置远程仓库
git remote add <name> <url>
然后使用远程名称推送
git push <name>解决方案
由于你使用 git init 初始化了仓库,git 不知道当你使用 git push 时要联系哪个服务器。
因此,我们必须向仓库添加一个服务器(在 git 术语中称为remote):
git_remote_add.sh
git remote add origin [email protected]:yourusername/yourrepository.git记住将 [email protected]:yourusername/yourrepository.git 替换为你的仓库的正确 URL。有效的示例 URL 包括:
https://github.com/ulikoehler/UliEngineering.git[email protected]:ulikoehler/UliEngineering.git
这添加了一个名为 origin 的服务器(remote add),URL 为 [email protected]:yourusername/yourrepository.git。
URL(最后一个参数)取决于你使用的服务器,对于 GitHub,你可以通过点击绿色的 Clone or Download 按钮获取 URL(HTTPS 或 SSH,两者都可以)。
现在你可以将现有数据推送到服务器。git push 本身第一次不会工作,因为 git 不会自动知道你要推送到 origin。因此我们必须使用 --set-upstream 告诉它未来的 git push 命令应自动推送到 origin:
git_push_set_upstream.sh
git push --set-upstream origin master如果此命令列出错误,你可能使用了错误的仓库 URL 或你没有使用正确的凭据(用户名/密码、SSH 密钥等)。
从现在起,你只需使用
git_push.sh
git push每次进行提交后以便将其推送到服务器。
注意: origin 不是特殊名称,它只是当你 git clone 仓库时 git 用于服务器的名称。因此它是你要推送的主服务器的标准名称。类似地,git 使用 master 作为默认分支名称。
Check out similar posts by category:
Git, Version Management
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow