登录GitHub,链接:https://github.com,进入首页,点击Start a project
新建仓库

下面配置仓库信息,如下

创建仓库成功,跳转到以下界面

上图中已经将上传项目到GitHub上的方法写清楚了,下面我们来实践
首先要确认电脑上已经安装了Git,没有的自行安装。
- 在电脑上新建Test文件夹,进入文件夹,里面添加几个文件,用作上传测试。
- 在文件夹中右键点击
Git Bash Here
,打来Git的命令行窗口。 - 接下来就是按上图中提示操作了,在命令行窗口中输入命令
git init
,回车,使Test文件夹加入git管理,如下图

- 输入
git add .
(不要漏了“.”),将Test目录下的全部内容添加到Git,然后可以用命令git status
查看你添加信息,下图显示我只添加了一个文件test.txt

- 输入
git commit -m "first commit"
,将项目提交到本地仓库,“”中的信息是本次提交的描述信息。
这里如果出现以下内容,则需要你输入自己的账号或名字

用上面提示的代码设置自己的邮箱或名字

再次运行git commit -m "first commit"
,运行成功

- 输入
git remote add origin https://github.com/alonglong/Test.git
,将本地仓库与GitHub仓库连接。

- 输入
git push -u origin master
,上传项目到Github。然后会跳出一个登录框要求输入GitHub的账号密码,按要求输入就可以。

项目提交成功,可以在GitHub上看到自己刚刚上传的test.txt文件

后续
如果在运行git push -u origin master
后出现下面的错误信息,则需要配置Git SSH服务

配置方法如下:
- 生成SSH秘钥对
命名行运行ssh-keygen -t rsa -C "你的GitHub邮箱账号"
,然后会提醒你输入key的名称,你可以不用输入,直接3个回车

- 上图红框部分是产生秘钥文件的路径,找到
id_rsa.pub
文件,用记事本打开,复制其中的内容 - 登录GitHub, 打开信息设置页面,添加生成的秘钥,如下




配置完成,再次运行git push -u origin master
,推送成功,但是可能还会出现下面这样的警告

图中的警告的大概意思就是:警告:为IP地址为13.229.188.59的主机(RSA连接的)持久添加到hosts文件中
虽然警告不影响使用,但是影响心情,还是处理掉吧,编辑电脑的hosts文件,新添下面一行:
13.229.188.59 github.com
windows的hosts文件路径为:C:\Windows\System32\drivers\etc
linux的hosts文件路径为:/etc/hosts
注意:
windows系统会出现权限不够无法修改hosts的情况,百度一搜一堆教程都是说右键属性修改权限什么什么的,麻烦的要死,最简单的就是是先以管理员身份打开编辑器,再在编辑器里打开hosts文件。
网友评论