*建立 Git Repository

  1. 建立 git repository 資料儲存目錄
    root@ip123:~# mkdir -p /srv/git
    
  2. 進入 git repository 資料儲存目錄
    root@ip123:~# cd /srv/git
    
  3. 建立一個空的 git repository python_pg.git,一般副檔名設定為 .git。
    root@ip123:/srv/git# git init --bare python_pg.git
    hint: Using 'master' as the name for the initial branch. This default branch name
    hint: is subject to change. To configure the initial branch name to use in all
    hint: of your new repositories, which will suppress this warning, call:
    hint:
    hint: 	git config --global init.defaultBranch <name>
    hint:
    hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
    hint: 'development'. The just-created branch can be renamed via this command:
    hint:
    hint: 	git branch -m <name>
    Initialized empty Git repository in /srv/git/python_pg.git/
    
  4. git repository python_pg.git 目錄產生的資料。
    root@ip123:/srv/git# ll python_pg.git/
    total 16
    drwxr-xr-x. 2 root root    6 Feb  3 07:38 branches
    -rw-r--r--. 1 root root   66 Feb  3 07:38 config
    -rw-r--r--. 1 root root   73 Feb  3 07:38 description
    -rw-r--r--. 1 root root   23 Feb  3 07:38 HEAD
    drwxr-xr-x. 2 root root 4096 Feb  3 07:38 hooks
    drwxr-xr-x. 2 root root   21 Feb  3 07:38 info
    drwxr-xr-x. 4 root root   30 Feb  3 07:38 objects
    drwxr-xr-x. 4 root root   31 Feb  3 07:38 refs
    
  5. Git 提供掛鉤 (hook) 事件觸發功能,在某些時間點執行客製化的工作,掛鉤檔都在 hooks 目錄下,範例檔都以 .sample 為副檔名,先使用範例 post-update.sample。
    root@ip123:/srv/git# mv python_pg.git/hooks/post-update.sample python_pg.git/hooks/post-update
    root@ip123:/srv/git# cat python_pg.git/hooks/post-update
    #!/usr/bin/sh
    #
    # An example hook script to prepare a packed repository for use over
    # dumb transports.
    #
    # To enable this hook, rename this file to "post-update".
    
    exec git update-server-info
    
  6. 變更掛鉤檔 post-updates 屬性為可執行。
    root@ip123:/srv/git# chmod +x python_pg.git/hooks/post-update
    
  7. 為允敨用戶經由 http push 到 git repository,必須在 config 配置檔中加入 http 章節,設定 「receivepack = true」。
    root@ip123:/srv/git# vi python_pg.git/config
    [core]
    	repositoryformatversion = 0
    	filemode = true
    	bare = true
    [http]
        receivepack = true