Easonの小站
首页项目帖子照片音乐友链联系关于
首页项目帖子照片音乐友链联系关于
封面

Git使用

写作时间:2026-07-10 17:40:43

‍

Git使用

基本流程

# 配置身份(只需一次)

git config --global [user.name](http://user.name) "你的名字"

git config --global [user.email](http://user.email) "你的邮箱"

# 初始化并关联远程仓库

git init

git remote add origin <https://github.com/用户名/仓库名.git>

git branch -M main

# 提交

git add .

git commit -m "提交说明"

# 推送

git push origin main

如果远程仓库已有内容

推送会被拒绝:

! [rejected] main -> main (non-fast-forward)

先拉取合并:

git pull origin main --allow-unrelated-histories

如果有同名文件冲突(CONFLICT (add/add)),选择保留哪边:

# 保留本地版本

git checkout --ours .

git add .

git commit -m "合并冲突"

# 或保留远程版本

git checkout --theirs .

git add .

git commit -m "合并冲突"

再执行一次 git push origin main。

常见问题

**not a git repository**

还没执行 git init。

**Author identity unknown**

执行开头的 git config 两行。

**src refspec main does not match any**

本地分支名不是 main,先 git branch 查看,用 git branch -M main 改名。

**推送时连接超时 / Connection reset / Failed to connect**

网络问题,不是命令错误。用代理软件时试试切换节点,一般换一个就能连上。

‍

Comments

文章评论

avatar

Eason

RECOMMENDED

Table of Contents

MOE萌ICP备20260809号

运行时间:计算中…

有幸与你相遇,您是本站第 — 位访客

© 2026 Eason. All Rights Reserved./RSS/Sitemap