Github Push
2026.03.25
笔记摘要 1407 Words
- Views
- Comments
目录索引
目录索引
Github push 笔记.
1️⃣ 进入目录
cd /<project>2️⃣ 删除旧的 Git 记录(关键)
- 如果有就执行
rm -rf .git3️⃣ 重新初始化
git init4️⃣ 添加文件
git add .5️⃣ 提交
git commit -m "提交备注"6️⃣ 绑定 GitHub 仓库
git remote add origin https://github.com/<username>/<repositoriesname>.git7️⃣ 推送
git branch -M maingit push -u origin main- 随后输入 github用户名 github token,注意不是密码是token 需要去申请
🚀 Github Token 生成
- 生成 Token
🏷️ https://github.com/settings/tokens
点击:Generate new token (classic)
- 权限勾选
👉 勾这个就够:repo
- 生成后复制
👉 会得到一个类似:ghp_xxxxxxxxxxxxxxxxx
⚠️ 注意:只显示一次!
问题集
error: failed to push some refs to 'https://github.com/<username>/<repositoriesname>.git'hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first integrate the remote changeshint: (e.g., 'git pull ...') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.方案一:先拉再推(最安全)
git pull origin main --rebasegit push origin main👉 推荐用 —rebase,提交历史更干净
如果出现冲突:
# 修改冲突文件git add .git rebase --continuegit push origin main方案二:强制覆盖远程(危险但干脆) 如果你确定:❗远程代码不重要(比如刚创建的仓库)
直接:
git push -f origin main👉 会覆盖 GitHub 上所有内容