-
概述
学习目标: 学会推送指定文件夹到github的指定仓库!
目的:全站白嫖jsdelivr的CDN加速(原因:其实hexo-theme-matery已经非常友好的为我们配置了CDN加速,因但是由于jsdelivr不对超过50M的进行加速,导致我的部分图片的CSS,JS无法正常加载,所以我就想进行多仓库来部署,是图片,JS和CSS放在不同的仓库,但是在网上没有找到别人造好的轮子( Ĭ ^ Ĭ ),只好自己动手了,顺便学习一下Git的相关使用方法,一举两得φ(>ω<*)
1.创建仓库
# 当前目录作为Git仓库
git init
#当前目录的newrepo文件夹作为Git仓库
git init newrepo
如果当前目录下有几个文件想要纳入版本控制,需要先用 git add 命令告诉 Git 开始对这些文件进行跟踪,然后提交:
$ git add *.c
$ git add README
$ git commit -m '初始化项目版本'
克隆仓库
git clone <repo> <directory>
参数说明:
- **repo:**Git 仓库。
- **directory:**本地目录。
下面这些写法等价
git clone http://github.com/CosmosHua/locate new
git clone http://github.com/CosmosHua/locate.git new
git clone git://github.com/CosmosHua/locate new
git clone git://github.com/CosmosHua/locate.git new
2.Git 基本操作
3.
4.
5.Git 远程仓库(Github及服务器)
添加远程库
git remote add [shortname] [url]
$ mkdir runoob-git-test # 创建测试目录
$ cd runoob-git-test/ # 进入测试目录
$ echo "# 菜鸟教程 Git 测试" >> README.md # 创建 README.md 文件并写入内容
$ ls # 查看目录下的文件
README
$ git init # 初始化
$ git add README.md # 添加文件
$ git commit -m "添加 README.md 文件" # 提交并备注信息
[master (root-commit) 0205aab] 添加 README.md 文件
1 file changed, 1 insertion(+)
create mode 100644 README.md
# 提交到 Github
$ git remote add origin git@github.com:tianqixin/runoob-git-test.git
$ git push -u origin master
github官方的:
创建储存库
echo "# pic11" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:guhailong18/pic11.git #改成自己的仓库
git push -u origin master
从命令行推送现有存储库
git remote add origin git@github.com:guhailong18/pic11.git
git push -u origin master
看当前配置有哪些远程仓库
$ git remote
origin
$ git remote -v
origin git@github.com:tianqixin/runoob-git-test.git (fetch)
origin git@github.com:tianqixin/runoob-git-test.git (push)
执行时加上 -v 参数,你还可以看到每个别名的实际链接地址。
报错解决:
不知道有没有人像我一样随便弄些东西都能搞出一大堆报错,真的是惨!也可能是我喜欢乱搞东西,希望大家不要像我一样瞎弄,到头来只有一堆报错!
fatal: unable to auto-detect email address
原因分析:这个是因为没有设置全局邮箱引起的,因为我有多个SSH,所以没有设置
解决办法:
找到工程目录的.git文件夹,打开之后找到config文件,在最后边加上一句话
[user]
email=your email
name=your name
“Connection closed by remote host”
解决办法:
如果原来是可以用ssh连接的, 突然连接不上通常是连接数过多导致的.
修改服务器上的这个文件:/etc/ssh/sshd_config 找到这行:
- # MaxSessions 10
error: src refspec master does not match any
引起该错误的原因是,目录中没有文件,空目录是不能提交上去的
解决方法
touch README git add README git commit -m 'first commit' git push origin master
参考链接:
https://www.runoob.com/git/git-remote-repo.html (大部分都是从这里抄学来的)