IntelliJ IDEA使用Git連線GitLab伺服器
1.搭建gitlab
2.使用git遷移專案到gitlab中
3.使用IDEA遷出專案
一:從零搭建gitlab伺服器
1.1 GitLab映象下載地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/
筆者使用的是CentOS 6.5和gitlab-ce-10.4.2-ce.0.el6.x86_64.rpm,大夥可以根據需要到官網下載相應版本。
1.2 安裝gitlab依賴項
[[email protected] gitlab]#yum install curl policycoreutils-python openssh-server openssh-clients postfix cronie -y
gitlab安裝的時候會要求要有policycoreutils-python庫,否則在安裝過程中會報錯並且提示需要policycoreutils-python庫,gitlab使用postfix傳送郵件,gitlab支援http和ssh兩種協議。
-
[[email protected] gitlab]# service postfix start#啟動postfix
-
[[email protected] gitlab]# chkconfig postfix on#設定為開機
-
[
1.3 安裝gitlab
使用ssh遠端連線工具(XShell)將上面下載的gitlab映象rpm傳輸需要安裝gitlab的伺服器上。之後使用rpm命令進行安裝。
[[email protected] gitlab]# rpm -ivh gitlab-ce-10.4.2-ce.0.el6.x86_64.rpm
1.4 啟動gitlab
[ [email protected] gitlab]# gitlab-ctl reconfigure
說明:預設安裝登入之後會提示需要重置root密碼。可以自己單獨設定一個複雜密碼後登入。gitlab本身採用80埠,如安裝前伺服器有啟用80,安裝完訪問會報錯。需更改gitlab的預設埠可以修改vim /etc/gitlab/gitlab.rb:external_url 'http://localhost:81',
每次重新配置,都需要執行sudo gitlab-ctl reconfigure 使之生效。
1.5 登入gitlab
開啟瀏覽器輸入gitlab伺服器的IP地址,本文gitlab伺服器的IP地址為http://192.168.199.102/,首次提示修改密碼,如下圖:
二:使用git遷移專案到gitlab中
2.1 登入gitlab建立一個空的project。
2.2 使用git命令列上傳程式碼。
<1>輸入git config --global user.name "root"
<2>輸入git config --global user.email "郵箱" --我這裡沒有輸入郵箱
<3>輸入git init
<4>輸入git remote add origin http://192.168.199.102/root/yangzr.git
<5>輸入git add .
<6>輸入git commit -m "初始化"
<7>輸入git push -u origin master 將程式碼推送到gitlab端
三 使用IDEA開發專案
3.1.配置好git的exe目錄路徑
3.2.idea中checkou選擇git,填上專案路徑http://192.168.199.102/root/yangzr.git
3.3.填入專案路徑之後,輸入賬戶密碼將程式碼遷出
3.4.使用git提交
新建一個readme檔案,使用git提交。
點選Commit File之後會彈出提交檔案和提交內容,在最右下面的有Commit和Commit and push按鈕,這裡需要注意一下使用git的commit之後還需要push一下才會提交到git伺服器中(gitlab)。