【原】無腦操做:Gitblit服務器搭建及IDEA整合Git使用

背景:雖然有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項目

相關文章
相關標籤/搜索