git安装、ssh秘钥生成及github配置

从零开始安装配置git环境,以及生成git的ssh秘钥,最后配置到gitlab等git代码托管平台上。

Quick Start

安装git客户端


生成ssh秘钥,以windows系统为例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

1)首先打开dos,查看是否已经存在ssh秘钥(没有密钥则不会有这个文件夹,有则备份删除)
cd ~/.ssh

2)生成密钥
ssh-keygen -t rsa -C "cuizhenjie@gmail.com"

3)直接按3个回车,密码为空。

4)最后得到了两个文件:id_rsa和id_rsa.pub

5)将生成秘钥设置为全局默认,(此处的用户名和邮箱填写刚生成秘钥所输入内容)

git config --global user.name "cuizhenjie"
git config --global user.email "cuizhenjie@gmail.com"

设置windows对大小写敏感
git config core.ignorecase false
git config --global gui.encoding utf-8

避免git status显示的中文文件名乱码
git config --global core.quotepath off


将生成秘钥配置到gitlab或github等平台

1
2
3
4
5
6

1)获取id_rsa.pub公钥内容,并复制
cat ~/.ssh/id_rsa.pub

2)打开http://github.com,登录后打开用户设置-》SSH密钥-》增加密钥,添加id_rsa.pub内容-》保存就设置完成了


从svn迁移到git

svn不包含多各分支处理办法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1)首先进入电脑工作目录
cd ~/dev/workspace

2) 定义svn提交记录作者映射到新的名字,比如定义到users.txt文件
格式为: svn username = New User <New User@example.com>
如果有多个,那就多行,不需要符号换行,将所有的提交者都做一次映射。

3) 执行转换命令(如果),projectname 为项目名称
git svn clone svn://192.168.1.111/dev/projects/projectname --authors-file=users.txt --no-metadata --no-minimize-url projectname

4)执行成功以后,进入projectname项目
cd projectname

5)关联到git远程仓库
git remote add origin https://github.com/cuizhenjie/projectname.git

6)执行push到git仓库
git push origin master


svn包含多个分支的处理办法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

1)首先进入电脑工作目录
cd ~/dev/workspace

2) 定义svn提交记录作者映射到新的名字,比如定义到users.txt文件
格式为: svn username = New User <New User@example.com>
如果有多个,那就多行,不需要符号换行,将所有的提交者都做一次映射。

3) 执行转换命令(如果),projectname 为项目名称
git svn clone svn://192.168.1.111/dev/projects/projectname --authors-file=users.txt --no-metadata --no-minimize-url projectname

4)执行成功以后,进入projectname项目
cd projectname

5)将svn commit都抓取下来
git svn fetch

6)在git中查看svn commit记录信息
git log --pretty=oneline

7)查看分支 -- svn tag的被解析为git分支 ,需转换一下
git branch -r

8)转换分支-tag
git tag tags_testtag origin/tags/tags_testtag

9)删除远程的分支(tags)
git branch -r -d origin/tags/tags_testtag

10)关联远程git项目地址
git remote add origin https://github.com/cuizhenjie/projectname.git

11)推送到远端的git的仓库中
git push origin master --tags

12)切换到分支
git checkout tags_testtag

13)提交分支到远程的仓库中
git push origin tags_testtag


others