详解如何使用 git 与 github(一)

使用 github 的人可能不用 git, 但用 git 的人一定会使用 github 。

下边我举例说明如何使用 git 与 github。我的任务是要把上一个教程《网页制作实现评论comment功能》中的代码上传到 github 备份,谁叫我有点健忘。

安装 Git 版本控制系统

打开下载网页,安装程序会以.exe 的形式自动下载到电脑上,然后按照提示一步步进行安装。我在第一次安装完成后,随意找了个文件夹点击右键,并没有发现 Git Init Here, 问题可能出在旧版 "msysgit" 安装后有 Git Init Here 选项,新的 Git 中不再有这个选项,因此普遍认为有三种解决方法:

  1. 修改注册表
  2. 安装 GitExtensions
  3. 使用 Git Base Here 打开命令行,运行git init
    我选择了最简单的第三种方法,如何学友们使用了其它方法解决了这个问题,请留言给我。
MyRepository.png

Windows 下载地址:https://git-scm.com/download/win

配置 Git

连接本地仓库与 github 需要设置 ssh key

$ ssh-keygen -t rsa -C "your_email@youremail.com"

请将 your_email@youremail.com 设置为你在 github 上注册的邮箱。
接下来设置密码,直接回车为不设置密码。按照提示,找到 .ssh 文件夹下的 id_rsa.pub 文件,打开复制下全部内容。

设置 github

登陆 github, 选择setting 选项。

SSH and GPG keys.png

添加 SSH key。

Add SSH .png

验证是否配置成功

  1. 在 github 上创建仓库。
Create a New Repository.png

2.使用 Git Bash 打开命令行,输入

$ ssh -T git@github.com

当看到 You’ve successfully authenticated, but GitHub does not provide shell access 时,证明已与 github相连。然后设置用户名和邮箱

$ git config --global user.name "your name"
$ git config --global user.email "your_email@youremail.com"

__注意: user.name 与 "your name"间存在空格,由于不认真,这简单的一步困扰了我好久。 __
3.右键点击要上传的仓库,选择 git bash,添加远程地址

$ git remote rm origin
$ git remote add origin git@github.com:yourName/yourRepo.git

yourName 是你在 github 上的用户名,yourRepo.git 是刚刚创建的仓库名。

尝试上传一个文件

1.创建 README.txt 文件

Add README.png

2.在命令行输入以下指令

$ git add README.txt
$ git commit -m "first commit"
$ git push origin master
Snapshot.png

3.查看 Github

Github snapshot.png

这一阶段至此就算是成功了,我们改天再继续聊。

不积跬步,无以至千里,让我们一起前进!

参考资料:
http://1ke.co/course/194
http://stackoverflow.com/questions/42053555/global-git-config-file-does-not-exist
http://stackoverflow.com/questions/38481534/installing-git-on-windows-10-unable-to-access-gitconfig
http://litreily.coding.me/brackets/git/2016/05/15/brackets-git-instructions.html
https://www.youtube.com/watch?v=MJUJ4wbFm_A

更多内容请关注我的网站 www.emiluo.com

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容