git将文件上传到github上的两种方法

上传到github上的文件一定不能超出规定,如果超出,则会卡在写入对象那一环节。

 

第一个方法,(在本地建立文件夹上传)

1 首先进入需要上传的项目文件夹,打开终端init

:~/kaggle/houseprice$ git init
初始化空的 Git 仓库于 /home/mocas/kaggle/houseprice/.git/

2. 将文件上传到本地暂存区和版本库,

$ git add .
$ git commit -m "上传自己的信息"
[master (根提交) a6b70db] 房价预测的代码复现
 13 files changed, 6826 insertions(+)
 create mode 100644 .idea/houseprice.iml
 create mode 100644 .idea/inspectionProfiles/profiles_settings.xml
 create mode 100644 .idea/misc.xml
 create mode 100644 .idea/modules.xml
 create mode 100644 .idea/other.xml
 create mode 100644 .idea/workspace.xml
 create mode 100644 Predictions.csv
 create mode 100644 data_description.txt
 create mode 100644 house1.py
 create mode 100644 house2.py
 create mode 100644 sample_submission.csv
 create mode 100644 test.csv
 create mode 100644 train.csv

3.在github上创建仓库,复制仓库地址http://abcd

 

4.将本地的仓库关联到github上,在origin后面粘贴仓库地址 http://abcd

$ git remote add origin https://github.com/mocas-usr/houseprice_com.git

5.上传代码到github远程仓库

执行完后,如果没有异常,等待执行完就上传成功了,中间可能会让你输入Username和Password,你只要输入github的账号和密码就行了。但是在这一步很多人执行会报错,报类似failed to push some refs to......的错误,那是因为本地代码目录缺失README.md文件。我们只需要先通过如下命令进行代码合并【注:pull=fetch+merge]

git pull --rebase origin master

$ git pull --rebase origin master
warning: no common commits
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
展开对象中: 100% (4/4), 完成.
来自 https://github.com/mocas-usr/houseprice_com
 * branch            master     -> FETCH_HEAD
 * [新分支]          master     -> origin/master
首先,回退分支以便在上面重放您的工作...
应用:房价预测的代码复现

7.执行远程推送

执行语句 git push -u origin master即可完成代码上传到github

git push -u origin master

$ git push -u origin master
对象计数中: 17, 完成.
Delta compression using up to 4 threads.
压缩对象中: 100% (16/16), 完成.
写入对象中: 100% (17/17), 220.94 KiB | 0 bytes/s, 完成.
Total 17 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/mocas-usr/houseprice_com.git
   b50bced..c267ee7  master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。

第二种方法 (从github仓库clone上传)

新建仓库,复制仓库地址http://abcd

 

将仓库克隆到指定地址

$ git clone https://abcd

就会出现初始化的仓库文件夹,进入出现的文件夹,cd test

接下来依次输入以下代码即可完成其他剩余操作:

git add .        (注:别忘记后面的.,此操作是把Test文件夹下面的文件都添加进来)

git commit  -m  ”提交信息”  (注:“提交信息”里面换成你需要,如“first commit”)

git push -u origin master   (注:此操作目的是把本地仓库push到github上面,此步骤需要你输入帐号和密码)

$ git add .
$ git commit -m "自己的信息"
$ git push -u origin master ## 这里可以不加 -u origin master 也可以成功

成功提交github

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值