快速自架一台git server

Duncan
Duncan
Jul 21, 2017 · 2 min read

我們這邊環境是利用Ubuntu(IP 172.20.3.18)

  • 安裝git
$ apt-get install git-core
  • 並在此git server上建立目錄存放所有的專案,這裡以/var/git為例
$ mkdir /var/git
  • 建立你的project,以test為例
$ cd /var/git
$ mkdir test.git
$ cd test.git
$ git --bare init
  • 建立群組以及使用者權限,這邊會建立一個git群組,並把使用者duncan加入此群組
$ sudo groupadd git
$ sudo usermod -a -G git duncan
$ sudo chgrp -R git /var/git
$ shdo chmod g+rwx -R /var/git
  • 假設我現在要把我的/tmp/test資料夾底下程式上傳到此git server,須做初始化的動作
$ cd /tmp/test
$ git init
  • 加入remote端的repository
$ git remote add origin ssh://duncan@172.20.3.18/var/git/test.git
  • commit你的程式碼,即完成
$ git add -A
$ git commit -m 'Initial Test Project'
$ git push origin master

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade