本地用git上传项目到GitHub

本文档介绍了如何将本地项目通过git上传到GitHub,包括基础操作如初始化git仓库、添加文件、提交和关联远程仓库。同时,也详细讨论了在上传过程中可能遇到的问题,如本地与远程库不一致的解决方法和上传文件过大的处理策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2019/02/25

上传到github的基础操作,以及遇到的小问题及解决方法。(以下以博主的一次上传为例)

基础操作:

  • 进入到本地的要上传的文件目录下:

cd /E/BUPT/Postgraduate/BIG data/bigdata/bigdata_phrase3

  • 在当前项目的目录中生成本地的git管理

git init

  • 将项目上所有的文件添加到仓库中的意思,如果想添加某个特定的文件,只需把.换成相应文件

git add .

  • 提交注释,相当于做个标记。""里面内容根据自己需要修改。

git commit -m “first commit”

  • 将本地的仓库关联到github上

git remote add origin https://github.com/darcy-shimmer/bigdata_phrase3.git

  • 把代码上传到github仓库

git push -u origin master


几个问题

  • ! [rejected] master -> master (fetch first)
    error: failed to push some refs to 'https://github.com/darcy-shimmer/bigdata_phrase3.git'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    这个问题是因为本地库和远程库内容不统一,需要把远程库里面的内容放到本地:

git pull origin master
(实在不行,就:git pull --rebase origin master)

然后再

git push -u origin master

  • remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
    remote: error: Trace: 5f2b1afe371384f955857faa1f5d0c57
    remote: error: See http://git.io/iEPt8g for more information.
    remote: error: File hive-kudu-mysql/phrase3/newdata_customer/customer is 271.25 MB; this exceeds GitHub's file size limit of 100.00 MB
    To https://github.com/darcy-shimmer/bigdata_phrase3.git
    ! [remote rejected] master -> master (pre-receive hook declined)
    error: failed to push some refs to 'https://github.com/darcy-shimmer/bigdata_phrase3.git'
    上传文件过大。详见 https://help.github.com/en/articles/working-with-large-files
    比较直接的方法:

git rm --cached hive-kudu-mysql/phrase3/newdata_customer/customer
git commit --amend -chead

然后

git push -u origin master

当然你也可以通过git reset [版本号]返回到添加前的某个版本号,本地删除大文件,再重新进行之后的操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值