1. Gitblit installation
1.1. Introduction to Gitblit
Git is a favorite of programmers in the field of version control. For open source projects, it can be hosted on GitHub for free, which is quite convenient. But hosting private projects on GitHub can be quite expensive. Some enterprises and units develop in the local area network, so how to use Git for code version control? We can build our own Git server locally . It is quite convenient to build a Git server on Linux, and there are many online materials. For details, please refer to Liao Xuefeng's official website - Git Tutorial - Installing Git . So how to build a Git server under Windows? Through comparison, it is found that Gitblit can easily build Git services on the Win platform . Gitblit is an open source git server java implementation, so the premise of using it is to install the Java runtime environment.
1.2, installation environment
Software: jdk 1.8.0_65, Gitblit1.8.0
Operating system: win 10 home edition
1.3. Installation steps
Step 1: Download Java and install Java, I am using jdk 1.8.0_65.
Step 2: Configure the Java environment variables.
Right-click the computer and select Properties > Advanced > System Settings > Advanced > Environment Variables > System Variables.
1. New: variable name: JAVA_HOME; variable value: C:\Program Files\Java\jdk1.8.0_65 (depending on your own installation path, mine is installed on the C drive)
2. New: variable name: CLASSPATH; variable value: %JAVA_HOME%/lib/dt.jar;%JAVA_HOME%/lib/tools.jar
3. Add: Find the PATH variable and select Edit. Add %JAVA_HOME%/bin;%JAVA_HOME%/jre/bin to the end of "variable value ".
Step 3: Verify that Java is installed successfully.
Enter the command to open a command line window:
ctrl + R
cmd
In the command line window, enter javac and press Enter. If the following message appears, the installation is successful.
Step 4: Download and install Gitblit , download address http://www.gitblit.com/
Click to download directly. After the download is complete, you can directly decompress it without installation. My decompression path is: C:\jstao\soft\itPackage\gitblit-1.8.0
Step 5: Configure Gitblit.
1. First create a folder for storing the project code. The folder I created here is C:\jstao\workspace\gitblitWorkspace
2. Enter the decompressed directory and enter the data folder. Open the defaults.properties file.
3. Locate git.repositoriesFolder and assign the value to C:\jstao\workspace\gitblitWorkspace
4. Continue to locate server.httpPort, configure the port number of the http protocol, the default 0 sign disables the http protocol, and the value here is 10010
5. Locate server.httpBindInterface and configure the IP address of the server
6. Locate server.httpsBindInterface and assign the value to localhost
7. Save and close the file.
8. Switch to the decompressed directory and double-click to run the gitblit.cmd batch file. It runs successfully, as shown in the figure:
9. After the service runs successfully, test the following. Enter the IP address in the browser : http://127.0.0.1:10010/ , the default username and password are both admin, which can be modified after logging in. It is recommended to modify. If you can access it normally, the deployment is successful .
10. Every time you start the Git service, you have to double-click the following gitblit.cmd batch file. Isn't it annoying? Is there an operation to automatically start the service when you turn it on? Of course there is! Let's take a look at the configuration steps.
11. Switch to the decompressed directory and open the installService.cmd file for configuration. Find the ARCH assignment as amd64 (64-bit OS, 32-bit for X86)
12. Under the ARCH line, add a new line, and the assignment path of CD is the decompression path ( note that there is no space after CD ):
SET CD=C:\jstao\soft\itPackage\gitblit-1.8.0
13. Set the startup parameter to an empty value, ie --StartParams="" ^
Finally , select the installService.cmd batch file and open it as an administrator.
If there is no exception, you can find the "gitblit" service in the Windows "Services" component. Then set the service startup type to "automatic", and the service will start automatically in the future.
1.4, create a repository
Step 1: Open the browser and enter the IP address. The initial user name is admin and the password is admin to log in to gitblit (the password can be modified, it is recommended to modify it)
Step 2: Click Create Repository.
Step 3: Enter name and description. Other values are fine by default and can be changed according to project requirements.
Step 4: Successfully create an empty repository and see some official tips. Users can push content to the warehouse according to the prompts.
Step 5: Create a user
Generally speaking, it is not recommended to use the administrator account admin for push. The normal operation is to push content to the warehouse on the user side (client). The administrator account admin is only responsible for managing the server site and does not involve actual business content. Including the operation of creating a repository, users can be authorized to perform it later. Create a new user action below.
5.1, admin login, click the user in the drop-down menu
5.2. Click "Add User" in the upper right corner to enter the Add User page.
After the general filling is completed, the attribute tab page can be filled in according to the actual situation, which is optional.
5.3. Fill in the access permission page to configure repository permissions.
5.3.1. Select the repository, select logit.git
5.3.2、赋予具体权限,R(克隆)一般赋予测试人选,RW(推送)、RWC(推送,创建ref)、RWD(推送,创建删除ref)、RW+一般赋予开发人员,选好之后,按添加按钮
5.3.3、最后,选择保存,创建成功
5.3.4、这里我创建了三个用户,libai为测试人员,dufu,baijuyi为开发人员
2、客户端Git安装
2.1、自行下载安装Git客户端
Git下载地址:https://git-for-windows.github.io/
2.2、配置git客户端
git本地用户配置,任意地方,右键打开Git Bash终端,输入命令行配置Git
$ git config --global user.name "jstao"
$ git config --global user.email "******@163.com"
演示,从本地向仓库推送一个新文件。
$ mkdir logitProject 新建一个文件夹logitProject
$ cd logitProject/ 进入到该文件夹
$ touch README.md 新建一个文件
$ git init
$ git add README.md
$ git commit -m "logit Project first commit."
$ git remote add origin ssh://[email protected]:29418/logit.git
$ git push -u origin master (在此需要输入密码,回车)
如图显示,本地向仓库推送成功。
接下来可以到网页端验证以下。如图所示,刷新浏览器可以看到
可以看到已经提交到了远程仓库。
2.3、免密码克隆(推送)操作
可以看到在推送的时候需要输入密码,每次推送都要输入密码。有没有一种操作,可以使得频繁的推送不需要密码呢?当然有,看一下怎么操作,主要操作就是客户端命令行创建SSH Key,通过以下命令:
$ ssh-keygen -t rsa -C "[email protected]"
然后到用户主目录下找到.ssh文件夹,下面生成了id_rsa和id_rsa.pub这两个文件,将pub文件中的内容复制,上传到Gitblit站点自己账户的->用户中心->ssh,添加成功,则以后操作通过ssh://协议操作,则可以不用密码。
2.4、在IDEA中使用Git
打开IDEA File->Setting (或者使用快加建ctrl+alt+s)
将git.exe配置到IDEA
配置完成,测试一下看看。点击Test
显示测试成功,可以开始拉项目了
跟着一步步操作就可以将项目拉到本地,可以进行正常开发了。
3、Tortoisegit安装使用
上面已经够用了,但是,一般情况下我们装个Git客户端Tortoisegit,更加方便我们的开发。
3.1、安装Tortoisegit
安装TortoiseGit-2.6.0.0-64bit.msi
安装TortoiseGit-LanguagePack-2.6.0.0-64bit-zh_CN.ms
Tortoisegit及语言包下载地址:http://tortoisegit.org/download/
注:Tortoisegit是Git的一个插件,Git程序本身还是要安装的,我们上面已经装好了。
3.2、使用Tortoisegit
右键Git克隆可以将远程仓库项目,克隆到本地。
完成开发后,可以提交到远程仓库。