17年我做了一个QAS的原型系统,想把它上传至GitHub供大家分享。我登录了GitHub,创建了一个仓库(repository),准备上传我的3个代码文件夹。我左折腾右捣鼓,成功上传了2个文件夹,但是第3个文件夹怎么也上传不上去,系统显示我的文件夹大小超过25M不能上传。于是,我就开始寻找解决办法,然后开启了我用Git上传GitHub项目文件夹之旅,,,
首先,进入GitHub官网,注册一个GitHub账号,需要邮箱、用户名、登录密码;
其次,进入Git官网,根据系统需求下载软件并安装,安装时会让你选择安装路径和仓库保存路径(repository directory);
然后,上传过程、遇到的问题及解决办法如下:
1. 将我要上传的3个代码文件夹放入一个总文件夹下,点击右键,选择 Git Bash Here,打开Git工具;
2. 生成 SSH key(通过SSH通信协议上传本地文件或文件夹到GitHub服务器):
- 输入 $ ssh-keygen -t rsa -C "your-email@163.com";
- 接下来会提示输入路径、登录密码等,建议不要输入,直接按三次回车,即默认路径 C:\Users\Administrator\.ssh\id_rsa.pub,默认没有登录密码;
- 打开路径中的 id_rsa.pub 文件,复制全部内容(即ssh key公钥)备用。
3. 创建ssh key 公钥:
- 登录GitHub账户,点击右上角用户头像下的小三角,找到Settings;
- 在左侧菜单栏中点击SSH and GPG keys;
- 选择 New SSH key,输入title(如:My SSH key),将刚才在 id_rsa.pub 中的复制的内容粘贴进来;
- 点击 add SSH key,则创建完成。
4. 在GitHub中创建仓库:
- 点击账户右上角的 “+” 号,选择 New repository;
- 填写 Repository name(因为我已经创建了QAS仓库了,所以Repository name 选择 test 作为演示),勾选下面的选项 Initialize this repository with a README,点击 Create repository;
- 页面跳转,生成一个仓库,选择 Settings;
- 向下滑动,找到 GitHub Pages,选择 Choose a theme;
- 随便选择一种风格,点击 Select theme;
- 回到Settings下,可以看到 GitHub Pages下面多了一个地址,这就是你的 github pages 网址;
- 看Source下的选项是否是 master branch,如果不是就选择master branch,如果是就不用管它;
5. 将文件夹下的文件添加到Git仓库:
- 回到Git工具界面,输入 $ git init ,初始化一个Git仓库,出现
Initialized empty Git repository in G:/MyGitRepository/test/.git/
- 输入 $ git remote add aname git@github.com:zdfan1007/test.git ,没有报错
- 输入 $ git pull aname master,出现
fatal: 'git@github.com:zdfan1007/test.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解决办法:
输入 $ git remote add origin git@gitserver:test.git
- 输入 $ git commit -m "A project written in 2017" (引号里面的内容是注释,可根据自己的项目情况进行备注),出现
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'Administrator@PC20180666666.(none)')
解决办法:
输入 $ git config --global user.email "your-email@163.com"
输入 $ git config --global user.name "zdfan1007"
- 重新输入 $ git commit -m "A project written in 2017" ,出现
On branch master
Initial commit
Untracked files:
QASystem/
WebCollectCrawler/
Word2VEC/
nothing added to commit but untracked files present
解决办法:
输入 $ git add QASystem
输入 $ git add WebCollectCrawler
输入 $ git add Word2VEC
- 再输入 $ git commit -m "A project written in 2017",出现
[master (root-commit) 9d93e6f] A project written in 2017
870 files changed, 1265634 insertions(+)
create mode 100644 QASystem/.classpath
create mode 100644 QASystem/.project
...
...
...
create mode 100644 Word2VEC/target/test-classes/test/Test.class
create mode 100644 Word2VEC/trainingSet/carVec.txt
6. 将Git仓库中的文件上传至GitHub:
- 输入 $ git push -u origin master ,出现
ssh: Could not resolve hostname gitserver: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
中间试图的解决办法:
输入 $ ssh -T git@github.com
出现 Hi zdfan1007! You've successfully authenticated, but GitHub does not provide shell access.
输入 $ git remote add aname git@github.com:zdfan1007/test.git
出现 fatal: remote aname already exists.
输入 $ git pull aname master
出现 fatal: 'git@github.com:zdfan1007/test.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
输入 $ git push aname master
出现 fatal: 'git@github.com:zdfan1007/test.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
输入 $ git remote add origin git@github.com:zdfan1007/test.git
出现 fatal: remote origin already exists.
输入 $ git pull --rebase origin master
出现 ssh: Could not resolve hostname gitserver: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
输入 $ ping github.com
出现 ???? Ping github.com [25.47.232.191] ???? 32 ????????:
???????
???????
???????
???????
25.47.232.191 ?? Ping ??????:
?????: ????? = 4??????? = 0????? = 4 (100% ???)??
输入 $ ssh -T git@github.com
出现 Warning: Permanently added the RSA host key for IP address '25.47.232.191' to the
list of known hosts.
Hi zdfan1007! You've successfully authenticated, but GitHub does not provide shell
access.
实际解决办法:
输入 $ git remote rm origin
输入 $ git remote add origin git@github.com:zdfan1007/test
- 输入 $ git push origin master ,出现
To github.com:zdfan1007/test
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:zdfan1007/test'
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 --rebase origin master
出现 warning: no common commits
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (7/7), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 7 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (7/7), done.
From github.com:zdfan1007/test
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
First, rewinding head to replay your work on top of it...
Applying: A project written in 2017
- 再输入 $ git push -u origin master ,成功
Warning: Permanently added the RSA host key for IP address '31.192.133.68' to the list of known hosts.
Enumerating objects: 806, done.
Counting objects: 100% (806/806), done.
Delta compression using up to 4 threads
Compressing objects: 100% (729/729), done.
Writing objects: 100% (805/805), 137.79 MiB | 272.00 KiB/s, done.
Total 805 (delta 128), reused 0 (delta 0)
remote: Resolving deltas: 100% (128/128), done.
remote: warning: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: warning: See http://git.io/iEPt8g for more information.
remote: warning: File QASystem/library/corpus01_model is 98.12 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
To github.com:zdfan1007/test
9fed167..20134cd master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
7. 查看上传的项目:
- 回到GitHub网站,点击你刚刚创建的test仓库
- 向下滑动,可以看到你上传的3个代码文件夹成功
- 多的两个文件,一个是你刚刚创建repository时勾选了 Initialize this repository with a README 选项而生成的,可以进行编辑,还有一个是你点击select theme,选择了一个theme而生成的theme文件。