在github上创建项目,博客
第一步,在github上建个仓库。
注:我这里是要创建一个zhangsx18.github.io的博客,所以仓库名称必须是zhangsx18.github.io . 不然会出现文章最后面的错误。
一个github帐号只能创建一个博客,博客的名称必须和用户名相同。
二、
https://desktop.github.com/ 下载github客户端,FQ不行的话,可以试试不FQ。
创建ssh:打开终端检测是否存在ssh:命令cd ~/.ssh
如果存在,先将已有的ssh备份,或者将新建的ssh生成到另外的目录下
如果不存在,通过默认的参数直接生成ssh
$ssh-keygen -t rsa -C xxxxx@gmail.com(注册github时的email)
三、
在github中添加ssh(如图示):
登陆github,选择Account Settings-->SSH Keys 添加ssh
Title:xxxxx@gmail.com,可以随便填
Key:打开你生成的id_rsa.pub文件,将其中内容拷贝至此。
四、
打开终端,先测试一下你的帐号跟github连上没有:ssh -T git@github.com 如果出现如下提示,表示你已经连上了.
五、
clone刚才新建的repository 到本地,输入命令:
git clone git@github.com:zhangsx18/zhangsx18.github.io.git
然后进入
touch README.md //新建一个记录提交操作的文档
git init //初始化本地仓库
git add README.md //添加
git add 项目包含的文件
git commit -m "first commit"//提交到要地仓库,并写一些注释
git remote add origin git@github.com:youname/Test.git //连接远程仓库并建了一个名叫:origin的别名
git push -u origin master //将本地仓库的东西提交到地址是origin的地址,master分支下
六、第五步容易出现的错误
(1)
如果git remote add origin git@github.com:youname/Test.git这一步失败
提示出错信息:fatal: remote origin already exists.
解决办法如下:
1、先输入$ git remote rm origin
2、再输入$ git remote add origin git@github.com:djqiang/gitdemo.git 就不会报错了!
3、如果输入$ git remote rm origin 还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的内容
4、找到你的github的安装路径,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc
5、找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!
如果是更新项目的话,进入项目目录然后执行
git add 项目文件
git commit -m "first commit"//提交到要地仓库,并写一些注释
git remote add origin git@github.com:youname/Test.git //连接远程仓库并建了一个名叫:origin的别名
git push -u origin master //将本地仓库的东西提交到地址是origin的地址,master分支下
即可:
更多细节可以参照下面的博客
下面添加一位参考的博主http://www.cnblogs.com/heyonggang/p/3462191.html
原文链接:http://www.jianshu.com/p/e7476c95a77f
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
(2)git push -u origin master 出现以下错误
error: failed to push some refs to 'https://github.com/CrazyDony/text.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.
出现错误的主要原因是github中的README.md文件不在本地代码目录中,
命令行中输入:
git pull--rebase origin master
git push -u origin master
然后又会出现
error: failed to push some refs to 'https://github.com/CrazyDony/text.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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 push origin master
出现
failed to push some refs to 'https://github.com/CrazyDony/text.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
原因:自己分支版本低于主版本
git push -u origin master-f
Counting objects: 35, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (29/29), done.
Writing objects: 100% (35/35), 10.15 KiB | 0 bytes/s, done.
Total 35 (delta 5), reused 0 (delta 0)
To https://github.com/CrazyDony/text.git
+ aa70966...f64b22a master -> master (forced update)
Branch master set up to track remote branch master from origin. 完成.
引用自:http://blog.csdn.net/crazydony/article/details/51983343
此问题另一种解决方法:
git pull
然后出现如下错误:
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
使用上面的命令就可以将本地的分支和远程分支进行关联了。<branch> 写master 就可以。
然后就可以git pull 了。
再一种方法:
http://blog.csdn.net/u010853261/article/details/51935503
具体操作不大确定,所以留个链接作参考。
点击 Launch automatic page generator .
其它问题
If you haven't initialized your submodule, you will need to initialize it with the following steps:
- In the submodule's directory, run
git submodule init
, thengit submodule update
. - Commit and push your changes to trigger another build on the server.