您的位置:首页 > 编程语言

git常用配置与使用

2017-08-17 17:17 405 查看

一、git安装

在使用Git前我们需要先安装 Git。Git 目前支持 Linux/Unix、Solaris、Mac和 Windows 平台上运行。

Git 各平台安装包下载地址为:http://git-scm.com/downloads

(1)windows 环境

完成安装之后,就可以使用命令行的 git 工具(已经自带了 ssh 客户端)了,另外还有一个图形界面的 Git 项目管理工具。
在 开始菜/右键/安装目录 单里找到"Git"->"Git Bash",会弹出 Git 命令窗口,你可以在该窗口进行 Git 操作。


安装包下载地址:http://msysgit.github.io/

二、git常用配置

1)个人信息配置

配置个人的用户名称和电子邮件地址,这是在你每次提交代码时的说明,知道谁提交了,联系谁

2. git config –global user.name “caiping”设置用户名

3. git config –global user.email 12800xxxx@qq.com 设置邮箱

4. git config –list查看git配置信息

2) github 无密钥登录配置(在git bash下面操作)

授权

ssh-keygen -t rsa -b 4096 -C “xxx@qq.com”

在本地git授权github,有两种方式授权HTTPS或者SSH

这里介绍SSH授权:

首先生成ssh key,出现提示一直回车



cat ~/.ssh/id_rsa.pub, 查看公钥,添加至http://github.com



测试是否配置成功

ssh git@github.com

3) 阿里Code无密钥登录配置 http://code.aliyun.com

生成SSH key

id_rsa_code_aliyun是SSH中的私钥,id_rsa_code_aliyun.pub则是SSH中对应的公钥,我们要把公钥的内容发布出去,自己保留私钥就可以了.

xx@yy:~/.ssh$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Generating public/private rsa key pair.

Enter file in which to save the key (/home/google/.ssh/id_rsa): id_rsa_code_aliyun

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in id_rsa_code_aliyun.

Your public key has been saved in id_rsa_code_aliyun.pub.

The key fingerprint is:

ff:af:52:d0:e8:23:4f:84:40:ae:5e:44:6a:cb:a7:0c your_email@example.com

The key's randomart image is:

+--[ RSA 4096]----+

|     .o          |

|     +.          |

|    o o. . o     |

|   o +  . + .    |

|  E + o So .     |

|   + +  ..+ .    |

|    +    +.o     |

|          o.     |

|           .oo.  |

+-----------------+

google@H:~/.ssh$ ls id_rsa_code_aliyun* -a

id_rsa_code_aliyun  id_rsa_code_aliyun.pub


添加公钥id_rsa_code_aliyun.pub到阿里云Code

用notepad++ 打开,ctr+a,ctr+c 复制(因为生成的公钥可能含有空格)

配置.ssh config文件

可以参考阿里云ssh的README

文件地址 ~/.ssh/config ,如果没有的话 touch config(新建一个config) 即可,然后在里面添加下面的内容
Host code.aliyun.com

HostName code.aliyun.com

IdentityFIle ~/.ssh/id_rsa_code_aliyun


验证连通成功

ssh -T git@code.aliyun.com

* Welcome to aliyun Code *

Hi ${your_email}, you have successfully connected over SSH.

To clone a hosted Git repository, use:

git clone git@localhost/REPOSITORY_NAME.git

如果没有配置config文件,报错如下:

ssh -T git@code.aliyun.com

The authenticity of host 'code.aliyun.com (120.55.150.20)' can't be established.

RSA key fingerprint is 69:ab:cb:07:eb:a3:e1:f3:0b:2e:f4:23:b0:c1:c6:9a.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'code.aliyun.com,120.55.150.20' (RSA) to the list of known hosts.

Received disconnect from 120.55.150.20: 2: Too many authentication failures


4) 中央仓库搭建, [b]gitblit[/b]

地址:http://gitblit.com/

参考http://blog.csdn.net/xtayfjpk/article/details/45669335

三、git常用命令



git clone 【ssh地址】 , 在当前目录下下载x.git文件

git state , 查看当前仓库信息信息

git pull origin master:master,git <拉取> <远程主机名> <远程仓库名?:<本地仓库名>

git push orgin master:master, git<推> <远程主机名> <本地仓库名>:<远程仓库名>

git checkout [branch-name],切换到指定分支,并更新工作区

参考:

http://www.cleey.com/Blog/single/id/760

https://kimown.github.io/2016/09/20/%E9%98%BF%E9%87%8C%E4%BA%91code%E9%85%8D%E7%BD%AEssh/

http://blog.csdn.net/xtayfjpk/article/details/45669335

http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息