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 init 和 git 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

9130

被折叠的 条评论
为什么被折叠?



