GitLab安裝配置使用總結

來源:互聯網
上載者:User

標籤:倉庫管理   管理工具   原始碼   下載安裝   新項目   

代碼管理一直用svn,Git的分支管理認為是最好的,嘗試用用。

一.GitLab簡介

GitLab 是一個用於倉庫管理系統的開源項目。使用Git作為代碼管理工具,並在此基礎上搭建起來的web服務。

可通過Web介面進行訪問公開的或者私人項目。它擁有與Github類似的功能,能夠瀏覽原始碼,管理缺陷和注釋。可以管理團隊對倉庫的訪問,它非常易於瀏覽提交過的版本並提供一個檔案曆史庫。團隊成員可以利用內建的簡單聊天程式(Wall)進行交流。它還提供一個程式碼片段收集功能可以輕鬆實現代碼複用。

下載安裝 https://bitnami.com/stack/gitlab/installer(此為一鍵安裝包,安裝很簡單,此處省略)

二.GitLab 的配置與使用

1.建立新項目(web)

1-1.登入gitlab網址成功後,點擊右側導航條上的 “+” 就可以進入建立項目的頁面

 650) this.width=650;" title="1.png" alt="1.png" src="http://ask.apelearn.com/uploads/questions/20161025/39a7d045e62c67e6e40ace502b88ef89.png" />


1-2.在建立工程的頁面,按照要求填寫項目的名稱和可見度等資訊。

Project path:項目的路徑,一般可以認為是項目的名稱

Import prject from:從哪匯入項目,提供Github/Bitbucket等幾個選項

Description(項目的描述):可選項,對項目的簡單描述

Visibility Level(項目可見層級):提供Private(私人的,只有你自己或者組內的成員能訪問)/Internal(所有登入的使用者)/Public(公開的,所有人都可以訪問)三種選項。


 650) this.width=650;" title="2.png" alt="2.png" src="http://ask.apelearn.com/uploads/questions/20161025/f1bdb85efab13d845ece99536f9b28a1.png" />

2.添加和配置SSH公開金鑰:

2-1.SSH(Secure Shell)是一種安全性通訊協定,在你的電腦與GitLab伺服器進行通訊時,我們使用SSH密鑰(SSH Keys)認證的方式來保證通訊安全。

2-2.建立 SSH密鑰,並將密鑰中的公開金鑰添加到GitLab,以便我們通過SSH協議來訪問Git倉庫。

SSH 密鑰的建立需要在終端(命令列)環境下進行,我們首先進入命令列環境。通常在OS X和Linux平台下我們使用終端工具(Terminal),在Windows平台中,可以使用Git Bash工具,git用戶端安裝目錄下git-bash.exe檔案


650) this.width=650;" title="3.png" alt="3.png" src="http://ask.apelearn.com/uploads/questions/20161025/b40c6fda2f2479d1e55fa1f0f75cfadb.png" />

A:進入SSH目錄:cd ~/.ssh

(1)如果還沒有 ~/.ssh 目錄,可以手工建立一個(mkdir ~/.ssh),之後再通過cd ~/.ssh進入SSH目錄

(2)可以通過ls -l命令查看SSH目錄下的檔案,來確認你是否已經產生過SSH密鑰;如果SSH目錄為空白,我們開始第二步B,產生 SSH 金鑰;如果存在id_rsa.pub這個檔案,說明你之前產生過SSH密鑰,如何添加多個sshkey也不難,一般很少用,這裡不介紹了。

B:產生SSH密鑰

我們通過下面的命令產生密鑰,請將命令中的[email protected]替換為你註冊gitlab時用的Email地址。

ssh-keygen -t rsa -C "[email protected]"

在SSH產生過程中會出現以下資訊,按螢幕的提示操作即可:

650) this.width=650;" title="4.png" alt="4.png" src="http://ask.apelearn.com/uploads/questions/20161025/9be6239fe4e93e2ff19d08dec8a9cf66.png" />


Note:Enter passphrase (empty for no passphrase) :時,可以直接按兩次斷行符號鍵輸入一個空的 passphrase;也可以選擇輸入一個 passphrase 口令,如果此時你輸入了一個passphrase,請牢記,之後每次提交時都需要輸入這個口令來確認。

實踐過程中Android studio 如果有密碼無法同步,建議不要密碼。

公開金鑰預設地址:C:\Users\使用者\.ssh 

串連git伺服器產生可信任檔案known_hosts,否則會報:Push failed: Failed with error: fatal: Could not read from remote repository.

Per Android Studio help under SSH Executable:

Built-in: select this option to use the implementation provided by IntelliJ IDEA.

Native: select this option to use native implementation.

修改SSH Executable 為 Native

3.擷取SSH公開金鑰資訊:

SSH密鑰產生結束後,根據提示資訊找到SSH目錄,會看到私密金鑰id_rsa和公開金鑰id_rsa.pub這兩個檔案,不要把私密金鑰檔案id_rsa的資訊透露給任何人。我們可以通過cat命令或文字編輯器來查看id_rsa.pub公開金鑰資訊。

(1)通過編輯器。使用你熟悉的文字編輯器,比如 記事本、Sublime Text等軟體開啟id_rsa.pub,複製裡面的所有內容以備下一步使用。

(2)通過cat命令。在命令列中敲入cat id_rsa.pub,斷行符號執行後命令列介面中會顯示id_rsa.pub檔案裡的內容,複製後在下一步使用。

(3)通過直接使用命令將id_rsa.pub檔案裡的內容複寫到剪下板中

Windows: clip < ~/.ssh/id_rsa.pub

Mac: pbcopy < ~/.ssh/id_rsa.pub

GNU/Linux (requires xclip): xclip -sel clip < ~/.ssh/id_rsa.pub

4.添加SSH公開金鑰到gitlab:

4-1.開啟gitlab的Profile配置頁面,選擇SSH Keys,

650) this.width=650;" title="5.png" alt="5.png" src="http://ask.apelearn.com/uploads/questions/20161025/3022e369934971c5e6fc784c24e73408.png" />



650) this.width=650;" title="6.png" alt="6.png" src="http://ask.apelearn.com/uploads/questions/20161025/03683e1b5694aa4a38ca402fe26f4e6c.png" />

4-2.添加SSH公開金鑰。填寫Title和Key,其中Title是Key的描述資訊,Key是上面複製的SSH公開金鑰的內容,直接粘貼到輸入框中儲存即可。

650) this.width=650;" title="7.png" alt="7.png" src="http://ask.apelearn.com/uploads/questions/20161025/4d4bb070758a9130bbb87e51502bab27.png" />



650) this.width=650;" title="8.png" alt="8.png" src="http://ask.apelearn.com/uploads/questions/20161025/b97aa5ad6fabe879e1df53d520b92df0.png" />

5、windows用戶端操作

此時開啟web找到你剛才建立的項目,下方會有相關操作配置提示

註:倉庫地址中的gitlab.example.com在以下用戶端配置中需換成你的伺服器ip地址。(原因是我用一鍵安裝包,未作詳細配置)


650) this.width=650;" title="9.png" alt="9.png" src="http://ask.apelearn.com/uploads/questions/20161025/51bed289ee20878c4893c6e49bc0edae.png" />

樣本:

用戶端開啟git bash

Command line instructions(命令列指令)

Git global setup(全域設定)

git config --global user.name "***"
git config --global user.email "****@qq.com"

Create a new repository(建立一個新的存放庫)複製

git clone [email protected]:ceshi/bbbbb.git
cd bbbbb
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Existing folder or Git repository(現有的檔案夾或Git存放庫)

#在本地的檔案夾空白處,右鍵選擇git bashgit init
git remote add origin [email protected]:ceshi/bbbbb.git
git add .
git commit
git push -u origin master

以上操作完可以愉快的,git add   、  git  commit   、git  push

6.匯入項目:

6-1.設定下git的使用者名稱和郵箱

在提交代碼前,還需要設定下git的使用者名稱和郵箱(最好用英文,不要出現中文),這樣提交記錄才會在gitlab上顯示帶有你名字的記錄。

在命令列視窗輸入(windows需要安裝開啟Git Bash工具才行):

git config --global user.name"your_name"

git config --global user.email "your_email"

6-2.導新項目到gitlab上

如果項目存在,需要匯入到gitlab,可以通過命令列直接將項目匯入上去。

[plain] view plain copy

cd "本地存在項目的路徑"  

git init  

git remote add origin [email protected]:USERNAME/PROJECTNAME.git  

git add .  

git commit -m ‘first git demo‘  

git push -u origin master  

(註:將USERNAME和PROJECTNAME替換成使用者名稱和項目的名稱)

6-3.匯入項目到本地

git clone"你的項目地址"

650) this.width=650;" title="10.png" alt="10.png" src="http://ask.apelearn.com/uploads/questions/20161025/b98e84cd317ecba25ef8a2c9bb7b6d7c.png" />

Note:如何在gitlab上找到你的項目地址位置,請看:

650) this.width=650;" title="11.png" alt="11.png" src="http://ask.apelearn.com/uploads/questions/20161025/81f516e6225acdcedcd2633a5742de36.png" />



650) this.width=650;" title="12.png" alt="12.png" src="http://ask.apelearn.com/uploads/questions/20161025/75d5a0389e914269522482ddca9f067b.png" />


GitLab安裝配置使用總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.