git日常问题

在2016年的时候,我建立了自己的github,当时只是跟风,觉得大家都在使用github,自己也要有一个,其次就是想有一个自己的博客,闺蜜之前自己搭载了一个gitpage+hexo的博客,容易上手,就想学一下,没想到过程坎坷= =。

到现在也不是很怎么会使用github,但是已经稍有了解了

什么是git:

之前我使用过svn进行和队友合作开发项目,觉得svn是一个很好的工具,可以避免代码冲突,解决团队代码的同步问题

有人拿git和svn比较,我觉得git更偏向于版本控制,就是自己对自己的代码进行控制,有了版本的概念和回滚,即使不是变成人员也可以使用,比如作家可以管理自己的作品。

关于git怎么使用的,百度可以搜出来一大堆,这里就不再赘述了,推荐廖雪峰老师的教程Git教程 - 廖雪峰的官方网站

现在来说一下我对github的初步认识
因为现在使用github还不是特别熟练,只指出最基本的,
首先要新建一个项目,然后有三种上传项目的方式:

  1. …or create a new repository on the command line 新建一个项目
echo "# 2017-02-23node1" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/sunshine940326/2017-02-23node1.git
git push -u origin master
  1. …or push an existing repository from the command line 通过命令行提交一个已有的项目
git remote add origin https://github.com/sunshine940326/2017-02-23node1.git
git push -u origin master
  1. …or import code from another repository 从其他项目引入
You can initialize this repository with code from a Subversion, Mercurial, or TFS project.

这里先埋一个坑,在第一种方法进行到git remote add origin这一步的时候一直报错Failed connect to github.com:443 显示超时
网上的解决方法没有看懂,先贴出来:git遇到的诡异错误: Failed connect to github.com:443

还有一个问题也是经常遇到的,不知道为什么隔一段时间我的github上的ssh都会变成灰色,这样本地就连接不上github,于是找到了解决方法:因为没有设置用户名和邮箱,解决方法如下:
“Git”->“Git Bash”,输入

$ git config --global user.name "Your Name"
$ git config --global user.email email@example.com
$ ssh -T Git@github.com

git config命令的–global参数,用了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地址。

执行完最后一步的时候,刷新github的setting页面,就可以看见ssh中的钥匙变成绿色的

但是在最后一步的时候报错了

ssh: connect to host github.com port 22: Connection timed out

解决方法是
在存放公钥私钥(id_rsa和id_rsa.pub)的文件里,新建config文本,内容如下:

Host github.com
User YourEmail@163.com
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

YourEmail为您的邮箱
再次执行”ssh -T [email protected]”时,会出现提示如下,回车”yes”即可。
这里写图片描述

这时验证就可以通过。

猜你喜欢

转载自blog.csdn.net/sunshine940326/article/details/56684119