背景:虽然有GitHub、GitLab这样强大的Git仓库,可是涉及私有Git库要收费,因此本身动手搭建免费的用用html
环境:windows 7 旗舰版、JDK 1.八、IDEA 2017git
-------------------------------------------------------------------------------------------------------------------------------------------web
一、Gitblit服务器搭建spring
1.一、下载最新版本的Gitblit,Gitblit官方网站:http://www.gitblit.com/,本文使用的是1.8.0版本apache
1.二、下载完毕后解压至D:\Java下,更名为gitblit(只是我的习惯,Java开发相关的东西都放在这儿),观察一下gitblit的目录结构,红色箭头标记的是将要修改和操做的部分windows
1.三、在data目录中将defaults.properties文件复制一份,更名为my.properties浏览器
1.四、打开gitblit.properties文件,注释掉include = defaults.properties这句,添加include = my.properties这句,说明使用的是my.properties配置文件服务器
1.五、找到server.httpPort,设定http协议的端口号: server.httpPort = 10101ssh
1.六、找到server.httpBindInterface,设定服务器的IP地址(本机IP地址):server.httpBindInterface = 192.168.20.7maven
1.七、找到server.httpsBindInterface,设定为localhost:server.httpsBindInterface = localhost
1.八、在D:\Java\gitblit目录同时按下shift+鼠标右键,找到"在此处打开命令窗口",输入gitblit.cmd
1.九、打开浏览器,在地址栏输入:https://localhost:8443/ 或 http://192.168.20.7:10101/,若是出现下图,说明服务器已经搭建完毕。默认帐号和密码均为 admin
-------------------------------------------------------------------------------------------------------------------------------------------
二、gitblit建立用户、版本库,并分配访问权限
2.一、使用admin帐号登陆服务器,建立用户,并分配访问权限
2.二、建立版本库,并设置版本库访问权限
点击"保存"按钮后,再用建立的temptation帐号登陆Git服务器观察一下,发现能够看到admin帐号建立并分配给temptation帐号访问的版本库
-------------------------------------------------------------------------------------------------------------------------------------------
三、Git客户端搭建
3.一、下载Git客户端最新版本,Git客户端官网:https://git-scm.com/downloads,下载完毕后打开,一路回车默认安装便可
3.二、Git本机配置,找到安装好的Git客户端,点击Git Bash
命令语句解释:
cd ~/.ssh:查看是否存在.ssh目录
mkdir ~/.ssh:若是不存在,则建立一个.ssh目录
git config --global user.name "帐号":设置git全局帐号
git config --global user.email "邮箱":设置git全局邮箱
ssh-keygen -t rsa -C "邮箱":生成SSH Key
3.三、在操做系统的用户目录下C:\Users\temptation\.ssh下,找到id_rsa.pub,将其中的内容复制出来
3.四、用建立的Git帐号temptation登陆Git服务器
3.五、将id_rsa.pub的内容贴到SSH Keys中,点击"添加"便可
-------------------------------------------------------------------------------------------------------------------------------------------
四、Git客户端使用
4.一、在想要建立项目的路径建立项目目录,好比:在D:\workspace下新建目录studygit
4.二、在目录studygit下,右键找到"Git Bash Here",将下图红色箭头标记部分复制贴入
4.三、再次刷新服务端,能够看到版本的提交
-------------------------------------------------------------------------------------------------------------------------------------------
五、IDEA整合Git使用(整合使用Maven管理的Springboot项目为例)
5.一、IDEA的Settings中设置Git的SSH executable为Native
5.二、打开上面建立的Git项目
5.三、在项目上右键,点击"Add Framework Support...",选中Maven
5.四、IDEA的Settings中设置Maven为本身配置的Maven(Maven设置能够参看:http://www.javashuo.com/article/p-fwoqarsm-dk.html)
5.五、在pom.xml文件中编写以下内容
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project xmlns="http://maven.apache.org/POM/4.0.0"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5 <modelVersion>4.0.0</modelVersion>
6
7 <groupId>cn.temptation</groupId>
8 <artifactId>studygit</artifactId>
9 <version>1.0-SNAPSHOT</version>
10
11 <!-- 使用spring boot的默认设置 -->
12 <parent>
13 <groupId>org.springframework.boot</groupId>
14 <artifactId>spring-boot-starter-parent</artifactId>
15 <version>2.0.4.RELEASE</version>
16 </parent>
17
18 <dependencies>
19 <!-- web -->
20 <dependency>
21 <groupId>org.springframework.boot</groupId>
22 <artifactId>spring-boot-starter-web</artifactId>
23 </dependency>
24 <!-- thymeleaf -->
25 <dependency>
26 <groupId>org.springframework.boot</groupId>
27 <artifactId>spring-boot-starter-thymeleaf</artifactId>
28 </dependency>
29 </dependencies>
30 </project>
5.六、在项目上使用快捷键F4,查看Problem并解决
5.七、编写Springboot项目内容(能够参看:http://www.javashuo.com/article/p-fwoqarsm-dk.html)
1 package cn.temptation; 2
3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5
6 @SpringBootApplication 7 public class Application { 8 public static void main(String[] args) { 9 // SpringBoot项目启动
10 SpringApplication.run(Application.class, args); 11 } 12 }
5.八、提交代码至Git服务器
-------------------------------------------------------------------------------------------------------------------------------------------
六、IDEA中直接使用已经建立好的Git项目