所需安装程序

  1. Bit Bash & Git GUI
  2. GitHubDesktop

配置Git密钥(SSH)

  1. 填写你都git账号信息
1
2
3
git config --global user.name "leewinmen"
git config --global user.email leewinmen@qq.com
ssh-keygen -t rsa -C "leewinmen@qq.com"

之后是ssh,到C:\Users\你的名字\ .ssh文件夹\ id_rsa.pub,打开它,复制到github或码云或者coding。具体可以看

http://blog.darler.cn/hexo-coming/#码云和coding的部署

这里需要回车3次

  1. 在Git中输入以下命令验证与github连接是否成功,
1
2
ssh -T git@github.com  #对于github
ssh -T git@e.coding.net #对于coding

输入yes回车
(4.1在git clone失败后使用)

开始操作

本地创建一个文件夹存放git,比如我是在桌面的test文件夹

1
2
3
4
cd desktop/test
git init #初始化命令,自行输入帐号密码
git pull git@github.com:jisuax/jisuax.github.io.git #拉取远程仓库
#建议使用ssh

如果只是要里面的代码,用git clone,克隆仓库到本地。

1
git clone https://github.com/leewinmen/leewinmen.github.io 

上传文件到仓库

需要先把需要上传的文件放到clone下来的文件夹对应位置

1
2
3
git add . #不要漏了后面空格加一个小写的句号
git commit -m"init project" #确认命令 init project是注解,可使用中文
git push -u origin master #同步到github

删除的文件or文件夹

1
2
3
4
5
6
cd xxx.github.io  #进入克隆下了的仓库文件夹,需要删除文件的目录下
git rm -f index.html #这里我需要删除index.html这个文件
git rm -r index #删除文件夹的命令,比如这里删除index文件夹,替上面第二步
git commit -m 'index.html' #对这个文件前面的操作进行确认
git remote add origin https://github.com/leewinmen/leewinmen.github.io.git
git push -u origin master #这样就把仓库里的某个文件删除了

-u origin master可换为你的仓库https,比如

1
git push https://github.com/leewinmen/leewinmen.github.io

其他

1
git status #查看git当前状态

总结

归根到底,删除或者增加,或者改动,就是一个思路。

1
git add .
1
git commit -m 'darler'
1
git push -u origin master

我遇到的坑

1.GitHub创建博客报错404 There isn’t a GitHub Pages site here.

解决方案:

1.进入setting

2.找到GitHub Page,点击Change theme(设置之后即可访问)

2.Git发生Another git process seems to be running in this repository.

解决方案:

到你的Git文件夹去 ,然后会发现文件夹里面多了一个.git文件,打开.git文件,然后找到index.lock删除

3.fatal: Could not read from remote repository.

1
2
3
ssh -T git@github.com  #对于github
ssh -T git@e.coding.net #对于coding
ssh -T git@git@codeup.aliyun.com #对于codeup

4.Please make sure you have the correct access rights and the repository exists.

1
git push --set-upstream git@github.com:leewinmen/leewinmen.github.io.git master