Linux git 在自己的服務器上建立 git 倉庫(repository)
服務器端:
在這里使用 ssh 方式登陸:
ssh [username]@server_address(建議用超級用戶登陸)
提示輸入密碼:......
進入某個文件夾(如果沒有 /git 文件夾,則自己創建)
cd /git
在 /git 文件夾下創建 git 倉庫文件夾
mkdir testRepository.git
初始化服務端 git 倉庫:
cd testRepository.git/
git --bare init
返回父目錄:
cd ..
查看文件的詳細信息:
ls -l
修改 testRepository.git 的用戶組:
chgrp [group] testRepository.git -R
ls -l
修改 testRepository.git 的所有者(如果有需要的話):
chown [user] testRepository.git -R
修改 testRepository.git 的 mod 權限
chmod 770 testRepository.git/ -R(770代表 owner權限:7,用戶組權限:7,other用戶權限:0)
chmod 775 testRepository.git/ -R(775 用於 shared 的倉庫, 具體查閱 git-daemon)
(重要)設置默認新建的文件和文件夾同屬於其父目錄的用戶組:
chmod g+s <directory> -R #以后新push的內容都會默認為屬於父目錄的組
(重要)設置文件夾子目錄和文件繼承父目錄訪問權限:
set -R -d -m g:[group_name]:rwx <directory> #以后在<directory>中創建的文件夾都會繼承父目錄的訪問屬性,這樣在多人合作的git項目中push之后不會出現有時候不能訪問的情況
本機端:
在自己的文件夾下(例如 testRepository),打開git bash
初始化為一個本地倉庫:
cd testRepository
git init
這時候會生成一個 .git 的隱藏文件,打開里面的 config :
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
與連接到遠程倉庫,也就是讓本地倉庫與服務器倉庫連接起來:
git remote add origin ssh://server_address/git/testRepository.git
這時候從新打開 config:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = ssh://username@server_address/git/testRepository.git
fetch = +refs/heads/*:refs/remotes/origin/*
隨便添加一些內容,添加追蹤文件:
git add -A
提交:
git commit -m 'first commit'
第一次把本地倉庫的內容推送到服務器倉庫,也就是設置 git push 的默認遠程分支和本地分支:
git push -u origin master #-u : --set-upstream,就是把本地一個分支和遠程的一個分支關聯起來,在 config 中會有相應的記錄
以后修改提交就可以不用任何參數:
git push