准备工作:
下载安装git:下载地址:http://code.google.com/p/git-osx-installer/downloads/list?can=3
注册github 账号。https://github.com/
创建 SSH:
打开terminal:
输入 .ssh 检查是否已经有存在的ssh
如果存在,先将已有的ssh备份,或者将新建的ssh生成到另外的目录下
如果不存在,通过默认的参数直接生成ssh
生成过程如下:
$ssh-keygen -trsa -C xxxxx@gmail.com(注册github时的email)
Generating public/private rsa keypair.
Enter filein which to save the key (/Users/twer/.ssh/id_rsa):
Createddirectory '/Users/twer/.ssh'.
Enterpassphrase (empty for no passphrase):
Enter samepassphrase again:
Youridentification has been saved in /Users/twer/.ssh/id_rsa.
Your public keyhas been saved in /Users/twer/.ssh/id_rsa.pub.
The keyfingerprint is:
18:16:11:c9:01:6c:48:09:7f:27:c6:43:0d:7f:3f:84 xxxxx@gmail.com
The key'srandomart image is:
+--[ RSA2048]----+
|.o.++=== |
|.ooo.+. . |
| ..* = E. |
| o = +o |
| . S o |
| . |
| |
| |
| |
+-----------------+
如果要修改ssh生成目录,在蓝色位置处输入要生成的路径,选择默认的话,会生成在~/.ssh下
在github中添加ssh:
Title:xxxxx@gmail.com
Key:打开你生成的id_rsa.pub文件,将其中内容拷贝至此
测试SSH:
$sshgit@github.com
Theauthenticity of host 'github.com (207.97.227.239)' can't be established.
RSA keyfingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are yousure you want to continue connecting (yes/no)? yes
Warning:Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.
PTY allocationrequest failed on channel 0
Hi xianfuying!You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
在蓝色位置处输入 yes
设置本地git个人信息:
$git config--global user.name "your real name"
$git config--global user.email "xxxxx@gmail.com"
至此,git和github的设置就完成了,下面就是如何将本地代码push到github上,以及如何从github上pull代码了:
在github中创建Repository:
https://github.com/ --> NewRepository 输入Repository信息 projectName
在本地创建代码库:
创建一个文件夹作为localrepository
$mkdir test
创建一个文件
$cd test
$vi test.txt
将文件添加至localrepository
$git addtest.txt
初始化localrepository
$git init
commit文件
$git commit -a
定义远程服务器别名
$git remote addalias git@github.com:xxxxx/projectName.git
将本地数据push到github上
$git push aliasmaster
这样就可以将本地的代码push到github的repository中了
从github中pull代码:
在github中搜到你想要pull的代码,如https://github.com/edgecase/ruby_koans
选择fork,将此repositoryfock到你的repository下
在本地创建localrepository并初始化
使用命令:
$git pullgit@github.com:xxxxx/ruby_koans.git
将github上的代码pull到localrepository中
转载出处:http://blog.163.com/xianfuying@126/blog/static/21960005201181482518631/