Github本地项目上传、大文件上传

185 阅读1分钟

本地项目上传步骤

cd 到本地项目目录

git init 
  • 众所周知,由于git init之后默认的分支名称叫master,我们需要更改为main分支,才能保证和远程Github新建的项目的主分支一致,所以要使用下面的命令将master分支,修改为main分支
git branch -m master main 
  • 添加远程分支
git remote add origin xxx
  • 推送
git push -u origin main
  • 报错处理

image.png

  • 2021年8月13日开始不在支持通过输入账号密码的形式push代码,需要使用personal access token个人访问令牌
  • 需要去github创建授权码

image.png

  • 只需要push代码,就按照下面创建个就行了

image.png

  • 接下来 我们需要先remote已经存在的关联的远程
git remote -v
git remote remote origin 

image.png

  • 接下来我们push代码使用下面的命令即可
git push https://你的token@github.com/github用户名/仓库名.git
  • 还是报错,本地main分支代码与远程分支main代码不同步,那么我们可以使用强制推送的命令强制覆盖远程分支即可
git push -f https://你的token@github.com/github用户名/仓库名.git
  • 大功告成~

  • 之后再创建的本地项目直接参照Github的提示来就行了

echo "# XXXXX" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/jiayuanfa/xxxxxx.git
git push -u origin main

解决github超过50MB或者100MB的大文件无法推送的问题

  • 安装git-lfs
brew install git-lfs
  • cd到项目目录
  • 初始化lfs
git lfs install
  • 指定大文件尾缀,因为是xxx.a文件所以
git lfs migrate import --include="*.a"
  • 然后
git push 

image.png

  • 移除LFS
git lfs uninstall