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


背景:雖然有GitHub、GitLab這樣強大的Git倉庫,但是涉及私有Git庫要收費,所以自己動手搭建免費的用用

環境:windows 7 旗艦版、JDK 1.8、IDEA 2017

-------------------------------------------------------------------------------------------------------------------------------------------

1、Gitblit服務器搭建

1.1、下載最新版本的Gitblit,Gitblit官方網站:http://www.gitblit.com/,本文使用的是1.8.0版本

1.2、下載完畢后解壓至D:\Java下,改名為gitblit(只是個人習慣,Java開發相關的東西都放在這兒),觀察一下gitblit的目錄結構,紅色箭頭標記的是將要修改和操作的部分

1.3、在data目錄中將defaults.properties文件復制一份,改名為my.properties

1.4、打開gitblit.properties文件,注釋掉include = defaults.properties這句,添加include = my.properties這句,說明使用的是my.properties配置文件

1.5、找到server.httpPort,設定http協議的端口號: server.httpPort = 10101

1.6、找到server.httpBindInterface,設定服務器的IP地址(本機IP地址):server.httpBindInterface = 192.168.20.7

1.7、找到server.httpsBindInterface,設定為localhost:server.httpsBindInterface = localhost

1.8、在D:\Java\gitblit目錄同時按下shift+鼠標右鍵,找到"在此處打開命令窗口",輸入gitblit.cmd

1.9、打開瀏覽器,在地址欄輸入:https://localhost:8443/ 或 http://192.168.20.7:10101/,如果出現下圖,說明服務器已經搭建完畢。默認賬號和密碼均為 admin

-------------------------------------------------------------------------------------------------------------------------------------------

2、gitblit創建用戶、版本庫,並分配訪問權限

2.1、使用admin賬號登錄服務器,創建用戶,並分配訪問權限

2.2、創建版本庫,並設置版本庫訪問權限

 

 

點擊"保存"按鈕后,再用創建的temptation賬號登錄Git服務器觀察一下,發現可以看到admin賬號創建並分配給temptation賬號訪問的版本庫

-------------------------------------------------------------------------------------------------------------------------------------------

3、Git客戶端搭建

3.1、下載Git客戶端最新版本,Git客戶端官網:https://git-scm.com/downloads,下載完畢后打開,一路回車默認安裝即可

3.2、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.3、在操作系統的用戶目錄下C:\Users\temptation\.ssh下,找到id_rsa.pub,將其中的內容復制出來

3.4、用創建的Git賬號temptation登錄Git服務器

3.5、將id_rsa.pub的內容貼到SSH Keys中,點擊"添加"即可

-------------------------------------------------------------------------------------------------------------------------------------------

4、Git客戶端使用

4.1、在想要創建項目的路徑創建項目目錄,比如:在D:\workspace下新建目錄studygit

4.2、在目錄studygit下,右鍵找到"Git Bash Here",將下圖紅色箭頭標記部分復制貼入

4.3、再次刷新服務端,可以看到版本的提交

-------------------------------------------------------------------------------------------------------------------------------------------

5、IDEA整合Git使用(整合使用Maven管理的Springboot項目為例)

5.1、IDEA的Settings中設置Git的SSH executable為Native

5.2、打開上面創建的Git項目

5.3、在項目上右鍵,點擊"Add Framework Support...",選中Maven

 

5.4、IDEA的Settings中設置Maven為自己配置的Maven(Maven設置可以參看:https://www.cnblogs.com/iflytek/p/8526182.html

5.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.6、在項目上使用快捷鍵F4,查看Problem並解決

5.7、編寫Springboot項目內容(可以參看:https://www.cnblogs.com/iflytek/p/8526182.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.8、提交代碼至Git服務器

-------------------------------------------------------------------------------------------------------------------------------------------

6、IDEA中直接使用已經創建好的Git項目

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM