windows下使用git管理github项目(入门)

原创
2013/03/23 09:18
阅读数 9K

本来的编写参看网上的两篇文章,两篇文章都不错,不过参照其中的任何一篇,在安装git和托管github项目的时候,都会存在一些问题,这里取两家之长,给出一个可操作性的文档说明,这也是本文写作的初衷。

本文简单介绍如何在windows下使用git及github仓库管理项目。

1 安装

目前windows版本的git有几种实现,但我们选择msysgit发行版,这是目前做得兼容性最好的。下载地址:http://code.google.com/p/msysgit/downloads/list

下载完成后双击安装文件并按照提示完成git的安装。git的安装过程十分简单,安装完毕后会提示你做初步的配置工作,这里我们全部按照默认值即可(PS:在选择git bash时我选择了类unix提示界面),安装完毕后git bash启动界面如下所示:


2 创建帐号

github是一个类似sf的免费项目管理及分享的服务平台,要想使用github提供的服务,你必须先注册成为github注册用户。github的网址是:http://github.com

3 建立本地git仓库

在D盘下创建目录git_repository(后续的项目都可以集中放在git_repository中),可以通过在git bash中执行以下命令完成:

cd /d
mkdir git_repository

4 生成SSH密钥

在git bash中执行以下命令完成:

ssh-keygen -C 'XX@gmail.com' -t rsa
一路按Enter键即可,当然如果你想选择使用密码功能,那么在提示输入密码是选择你自己的密码。过程如下图所示:



注意:ssh-keygen中的邮箱请使用github注册用户时使用的邮箱。

登陆github系统。点击右上角的Edit your profile---> Account Settings--->SSH Public keys ---> add another public keys,把你本地生成的密钥复制到里面(key文本框中), 点击 add key 就ok了。

测试连接是否成功,在git bash中执行以下命令完成:

ssh -T git@github.com

提示如下信息说明连接成功:

5 创建一个项目

5.1 回到github首页,点击页面右下角“New Repository”

填写项目信息:

project :hello-world

description : my first project

点击“Create Repository” ; 现在完成了一个项目在github上的创建。


5.2 使用git在本地创建一个相同的项目

$ git config --global user.name "John Doe"
$ git config --global user.email pp

$ mkdir ~/hello-world    //创建一个项目hello-world
$ cd ~/hello-world    //打开这个项目
$ git init    //初始化 
$ touch README
$ git add README   //更新README文件
$ git commit -m 'first commit'//提交更新,并注释信息“first commit” 
$ git remote add origin git@github.com:account/hello-world.git //连接远程github项目  
$ git push -u origin master   //将本地项目更新到github项目上去
现在查看github上面的hello world 项目,是不是发现已经将本地中的README文件更新上来了。 :) 恭喜!

5.3 可能出现的问题

5.3.1 问题一

执行下面语句报错

git remote add origin git@github.com:defnngj/hello-world.git

错误提示:fatal: remote origin already exists.

解决办法:

git remote rm origin

然后在执行:

$ git remote add origin git@github.com:defnngj/hello-world.git

5.3.2 问题二

执行下面语句报错

git push origin master

错误提示:error:failed to push som refs to.......

解决办法:

$ git pull origin master //先把远程服务器github上面的文件拉先来,再push 上去。






展开阅读全文
加载中

作者的其它热门文章

打赏
5
7 收藏
分享
打赏
4 评论
7 收藏
5
分享
返回顶部
顶部