# Gitlab從零開始安裝教學 (Windows) Gitlab官網: https://gitlab.com/ ## 1. 註冊並完成基本資料設置 在Gitlab官網註冊並登入, 到了需要填寫公司那頁如果沒有的話可以直接跳回官網 完成後可以在右上角頭像選擇Edit profile的左邊列選擇Account修改用戶名, 使得你個人的Gitlab主頁變成https://gitlab.com/用戶名 ## 2. 建立存儲庫 點擊Create blank project, 建立空白的存儲庫 ![](https://i.imgur.com/PyJ2HHB.png) 以及撰寫Readme等等 ![](https://i.imgur.com/ajdUOUK.png) ## 3. 安裝Git https://git-scm.com/ 從這裡下載Git並照著指示安裝 ## 4. 安裝及配置SSH Key 於CMD輸入 ```bash= ssh-keygen -t rsa ``` 下面這行意思是保存路徑, 默認為C:\Users\用戶名\\.ssh\id_rsa Generating public/private rsa key pair. Enter file in which to save the key(路徑) 接著兩個問題為密碼和確認密碼, 不需要的話直接Enter 在C:\Users\用戶名\\.ssh\文件夾中新建一個名稱為config的文件, 記事本打開 將下面內容複製貼上並保存, 最後一行記得換成你的id_rsa路徑 ``` # Gitlab Host gitlab.com HostName gitlab.com PreferredAuthentications publickey AddKeysToAgent yes IdentityFile C:\Users\用戶名\.ssh\id_rsa ``` 將ssh-key添加到ssh-agent ```bash= start-ssh-agent.cmd ``` 接著到剛才的保存目錄用記事本打開id_rsa.pub, 全選複製 回到Gitlab, 點頭像->Edit profile->左邊SSH Keys ![](https://i.imgur.com/0kXIgVe.png) 在中間SSH Fingerprints中貼上剛才複製的內容Add key就完成了 ## 5.配置本地Git 在目標文件夾初始化本地git存儲庫 ```bash= git init ``` 添加git遠端儲存庫 (如果還沒創建的話創建一個) 並複製下圖的Clone with SSH ![](https://i.imgur.com/Ekvttz4.png) ```bash= git remote add 名稱 上面複製的那串git@gitlab.com:.... ``` 接著以下是git常用命令 ```bash= git branch # 查看當前分支 git branch -m main # 將當前分支名稱修改成main git checkout -b main # 新建並切換到分支main git add --all # 將當前文件夾內的所有東西添加到上傳佇列 git commit -m "訊息" # 將上傳佇列中的內容提交到本地存儲庫, -m及訊息內容不能少 git push 遠端名稱 分支名稱 # 將本地存儲庫內容推送到遠端存儲庫, 遠端名稱為remote創建的名稱, gitlab默認分支是main git pull 遠端名稱 分支名稱 # 將遠端庫拉取到本地 git clone 儲存庫網址 # 下載那個儲存庫的全部內容到當前目錄 ```