【无标题】

GitHub 项目上传与分支管理快捷手册


适用场景:

  • 第一次把本地项目上传到 GitHub
  • 后续修改后快速更新
  • 使用 Git LFS 上传 ZIP、模型、固件等大文件
  • 把“第二版”作为独立分支上传
  • 处理常见报错

0. 使用前先确认

在项目文件夹空白处右键:

Open Git Bash here

检查当前目录:

pwd
ls

检查 Git 和 Git LFS:

git --version
git lfs version
git lfs install

首次配置身份:

git config --global user.name "wuyuwei885-netizen"
git config --global user.email "wuyuwei885@gmail.com"

一、新项目第一次上传

cd "/c/Users/PC/Desktop/项目名"

git init
git branch -M main
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/wuyuwei885-netizen/项目名.git
git push -u origin main

以后不再重复执行 git initgit remote add origin


二、包含大文件时使用 Git LFS

配置常见大文件:

git lfs install
git lfs track "*.zip"
git lfs track "*.img"
git lfs track "*.rknn"
git lfs track "*.onnx"
git lfs track "*.pt"
git lfs track "*.pth"
git lfs track "*.bin"
git lfs track "*.tar"
git lfs track "*.tar.gz"

检查:

cat .gitattributes
git lfs ls-files

提交和上传:

git add .gitattributes
git add .
git commit -m "Add project files and large assets"
git push -u origin main

如果 LFS 已上传,但 GitHub 页面没变化:

git lfs push origin main
git push origin main

git lfs push 只上传大文件本体,最终仍必须执行普通 git push


三、以后更新项目的快捷命令

cd "/c/Users/PC/Desktop/项目名"

git status
git add -A
git commit -m "Update project"
git push

一行版:

git add -A && git commit -m "Update project" && git push

如果出现:

nothing to commit, working tree clean

表示没有新修改。


四、把第二版上传为新分支

推荐结构:

main        第一版
v2-evolved 第二版

假设目录:

父目录/
├── LingeringPersonCleaner/
└── 第二版/

执行:

cd "/c/Users/PC/Downloads/Compressed/LinguaClip-main_3/LinguaClip-main/LingeringPersonCleaner"

git status
git switch -c v2-evolved

find . -mindepth 1 -maxdepth 1 ! -name ".git" -exec rm -rf {} +

cp -a "../第二版/." .

git add -A
git status
git diff --cached --stat
git commit -m "Add evolved v2 of LingeringPersonCleaner"
git push -u origin v2-evolved

切换版本:

git switch main
git switch v2-evolved

比较两版:

git diff --stat main..v2-evolved

五、分支名不一致

查看当前分支:

git branch --show-current

v2 改名为 v2-evolved

git branch -m v2-evolved
git push -u origin v2-evolved

报错:

src refspec v2-evolved does not match any

通常表示:

  • 本地没有该分支
  • 当前分支还没有 commit

检查:

git branch
git log --oneline -3
git status

六、远程仓库管理

查看:

git remote -v

添加:

git remote add origin https://github.com/wuyuwei885-netizen/项目名.git

如果提示:

remote origin already exists

改地址:

git remote set-url origin https://github.com/wuyuwei885-netizen/项目名.git

SSH 地址:

git remote set-url origin git@github.com:wuyuwei885-netizen/项目名.git

七、常见报错

1. fetch first

git pull origin main --allow-unrelated-histories
git push origin main

进入 Vim 时:

Esc
:wq
回车

2. Permission denied (publickey)

说明 SSH 公钥未配置。最简单是切回 HTTPS:

git remote set-url origin https://github.com/wuyuwei885-netizen/项目名.git
git push -u origin 当前分支名

3. Connection was reset 或超时

git config --global http.version HTTP/1.1
git push

大文件分开上传:

git lfs push origin main
git push origin main

第二版分支:

git lfs push origin v2-evolved
git push origin v2-evolved

4. 文件超过 100 MB

git rm --cached "大文件路径"
git lfs track "*.zip"
git add .gitattributes
git add "大文件路径"
git commit -m "Track large files with Git LFS"
git push

检查:

git lfs ls-files

5. 中文文件名显示转义字符

git config --global core.quotepath false

6. CRLF 警告

.gitattributes 中加入:

*.sh text eol=lf
*.py text eol=lf
*.dts text eol=lf
*.dtsi text eol=lf
*.md text eol=lf

Git Bash 写入命令:

cat >> .gitattributes <<'EOF'

*.sh text eol=lf
*.py text eol=lf
*.dts text eol=lf
*.dtsi text eol=lf
*.md text eol=lf
EOF

然后:

git add .gitattributes
git commit -m "Normalize line endings"
git push

八、最常用的四套快捷命令

新项目首次上传

cd "/c/Users/PC/Desktop/项目名"
git init
git branch -M main
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/wuyuwei885-netizen/项目名.git
git push -u origin main

普通更新

cd "/c/Users/PC/Desktop/项目名"
git add -A
git commit -m "Update project"
git push

大文件项目首次上传

cd "/c/Users/PC/Desktop/项目名"
git init
git branch -M main
git lfs install
git lfs track "*.zip"
git lfs track "*.rknn"
git lfs track "*.img"
git add .
git lfs ls-files
git commit -m "Initial commit"
git remote add origin https://github.com/wuyuwei885-netizen/项目名.git
git push -u origin main

第二版分支上传

cd "/c/Users/PC/Downloads/Compressed/LinguaClip-main_3/LinguaClip-main/LingeringPersonCleaner"
git switch -c v2-evolved
find . -mindepth 1 -maxdepth 1 ! -name ".git" -exec rm -rf {} +
cp -a "../第二版/." .
git add -A
git commit -m "Add evolved v2"
git push -u origin v2-evolved

九、每次操作前的安全检查

pwd
git status
git branch --show-current
git remote -v

标准流程:

确认目录
→ 查看状态
→ 添加文件
→ 提交
→ 推送

对应命令:

pwd
git status
git add -A
git commit -m "说明本次修改"
git push
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

oisflo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值