以下命令如果權(quán)限不夠昆烁,請使用sudo
安裝git
#centos
yun install git
或者
#ubuntu
apt install git
添加git用戶
useradd git
passwd git
#下面為輸出
Retype new password:
passwd: all authentication tokens updated successfully.
#如果密碼不符合系統(tǒng)規(guī)范都许,會提示相關(guān)錯誤镶摘,但是不影響盲憎,重新設(shè)置就行了纫版。
切換用戶
su git
cd ~/
mkdir gitRepo
cd gitRepo/
mkdir testGitReop.git
cd testGitReop.git/
git --bare init
命令參考:
su
使用
至此凿菩,git倉庫已經(jīng)建立好了机杜。其實,新建用戶的名字不一定要git衅谷,其他也可以椒拗。或者直接使用root用戶也可以获黔。但是蚀苛,在提交工程時,需要輸入git服務(wù)器對應(yīng)用戶的密碼玷氏,所以使用root不安全堵未。
- 沒有新工程,直接同步
git clone git@git-server-address:/home/git/gitRepo/testGitReop.git
#此處盏触,需要使用到git目錄的絕對路徑渗蟹,使用git用戶的相對路徑會報錯:'/git/gitRepo/testGitReop.git' does not appear to be a git repository
- 有工程,需要添加到遠程倉庫并推送
cd myproj-dir
git remote add origin git@git-server-address:/home/git/gitRepo/testGitReop.git
git add .
git commit -m 初始化工程
git push -u origin master
其他
如果本地工程的remote地址錯了赞辩,需要修改:
- 修改命令:
git remote set-url origin [url]
- 先刪除雌芽,再添加
git remote rm origin
git remote add origin [url]
- 直接修改cnfig文件:
cd .git/
vim ./config
#修改[remote "origin"] 的 url 的值
- 使用ssh key:
后面補充。辨嗽。世落。