# 致命错误：未配置推送目标。请从命令行指定URL，或使用'git remote add <name> <url>'配置远程仓库，然后使用远程名称推送。

- **ID:** `git/remote-origin-mismatch`
- **领域:** git
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

仓库没有配置用于推送的远程，或未设置上游分支，导致'git push'在没有明确目标时失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.39.0 | active | — | — |
| 2.40.0 | active | — | — |
| 2.41.0 | active | — | — |

## 解决方案

1. ```
   添加远程仓库：'git remote add origin https://github.com/user/repo.git'。然后推送：'git push -u origin main'。'-u'标志设置上游，以后只需'git push'即可。
   ```
2. ```
   如果远程已存在但未设置上游，请设置：'git branch --set-upstream-to=origin/main'。然后使用'git push'推送。
   ```

## 无效尝试

- **Running 'git push origin main' without checking if 'origin' remote exists.** — If the remote 'origin' doesn't exist, this will fail with 'fatal: 'origin' does not appear to be a git repository'. (70% 失败率)
- **Manually editing .git/config to add a remote without using 'git remote add'.** — This can work if done correctly, but is error-prone and may cause syntax issues. Better to use the git command. (40% 失败率)
- **Using 'git push --all' to push all branches at once.** — This still requires a remote destination; without one, it fails with the same error. (80% 失败率)
