Git入門操作

2021-07-10 02:34:14 字數 2549 閱讀 1614

僅學習git的一些入門操作比較容易,平時更多地使用github,不過今天我想自個搭個服務練練手。當看完一些材料合作了一些驗證之後,才發現其實所謂的服務和之前的svn完全不一樣了。過程記錄如下:

linuxserver端安裝git

還好一路順利:

$ git --version

git version

2.5.3

server端ssh配置

1)如果client端沒有建立ssh rsa公鑰,則先建立:

$ cd ~$ 

ssh-keygen -t rsa # 預設存放路徑在~/.ssh/id_rsa.pub

2)如果client端已建立,並存在~/.ssh/id_rsa.pub,則將其拷貝到server端:

$ ssh

@:.ssh/authorized_keys

id_rsa.pub

100% 416

0.4kb/s 00:00

3)修改server端的sshd_config:

$ ssh

@$ cd /etc # 有的機器在/etc/ssh下面

$ sudo

chmod

666sshd_config

$ vi

sshd_config

#permitrootlogin yes     改為 permitrootlogin no

# 下面幾項把前面的 #注釋 去掉

#rsaauthentication yes

#pubkeyauthentication yes

#authorizedkeysfile .

ssh/authorized_keys

#passwordauthentication no

#permitemptypasswords no

#usepam yes          改為 usepam no

測試是否有效

1)在server端建立空的repository

$ cd repo

$ git init -—bare # -—bare flag 只是用來儲存pushes,不會當做本地repository來使用的。

2)在client端建立repository 並push

$ mkdir

localrepo

$ cd localrepo

$ git init

$ touch

readme

$ git add .

$ git commit -m 「add readme」

$ git remote add origin

@:/repo

$ git push origin master

3)在client端clone剛剛建立的repository

$ git clone @:/repo localrepo2

發現剛剛提交的**樹被clone下來,說明搭建成功

由於git是分布式的,沒有主從之分,所以我理解所謂搭建git服務,其實就是確保有許可權訪問「伺服器」上的git檔案。這與該檔案是在遠端還是本地是無關的。比如上面的例子中,如果我把伺服器放在本地,一樣是可以的。

驗證伺服器搭建在本地

1)在本地建立空的repository

$ mkdir ~/repo

$ cd ~/repo

$ git init —bare

2)在本地建立repository 並push

$ mkdir ~/localrepo

$ cd ~/localrepo

$ git init

$ touch

readme

$ git add .

$ git commit -m 「add readme」

$ git remote add origin ~/repo

$ git push origin master

3)在本地clone剛剛建立的repository

$ git clone ~/repo ~/localrepo2

檢視~/localrepo2,果然readme被轉殖過來了。

Git入門操作

git 全域性設定 git config global user.name aaa git config global user.email aaa 163.com 建立 git 倉庫 mkdir book notes cd book notes 把這個目錄變成git可以管理的倉庫 git init...

Git入門操作

git config global username 使用者名稱 global 可以簡寫為 g 建立乙個使用者名稱 git config global emaill 郵箱 建立乙個郵箱 git diff 檢視當前暫存區跟本地檔案的不同,如果沒有輸出,那麼代表暫存區沒有東西 git log 檢視歷史提...

Git入門操作

僅學習git的一些入門操作比較容易,平時更多地使用github,不過今天我想自個搭個服務練練手。當看完一些材料合作了一些驗證之後,才發現其實所謂的服務和之前的svn完全不一樣了。過程記錄如下 linuxserver端安裝git 還好一路順利 git version git version 2.5.3...