Notebook

これは日々の作業を通して学んだことや毎日の生活で気づいたことをを記録しておく備忘録である。

HTML ファイル生成日時: 2025/02/19 17:13:34.229 (台灣標準時)

git server を準備して新しいリポジトリーを作る方法について

以下は、 git の server を準備し、新しいリポジトリーを作り、それを使え るようにする記録でござる。

まず、 git server を動かす計算機で git というアカウントを作るでござる。


% su -m -
# useradd -m -u 12345 -g 12345 git

git アカウントに切り替えるでござる。


# su -l git
% whoami
git
% pwd
/home/git

ホームディレクトリーに .ssh というディレクトリーを作り、 そこに空の authorized_keys というファイルを作っておくでご ざる。


% mkdir .ssh
% chmod go-rx .ssh
% cd .ssh
% touch authorized_keys
% ls -lF
total 0
-rw-r--r--  1 git  git  0 Feb 11 19:42 authorized_keys
% chmod go-r authorized_keys
% ls -lF
total 0
-rw-------  1 git  git  0 Feb 11 19:42 authorized_keys

利用したいアカウントが接続できるように、公開鍵を authorized_keys に追加するでござる。


% cat /somewhere/in/the/disk/id_ed25519.pub >> authorized_keys
% ls -lF
total 4
-rw-------  1 git  git  96 Feb 11 19:43 authorized_keys

リポジトリーのためのディレクトリーを作るでござる。


# mkdir /nas1/git_repository
# exit
% cd
% pwd
/home/git
% ln -s /nas1/git_repository repo
% ls -F
repo@
% cd repo
% mkdir daisuke_cfgfiles
% ls -lF
total 8
drwxr-xr-x  2 git  git  4096 Feb 11 19:49 daisuke_cfgfiles/
% cd daisuke_cfgfiles

新しい空のリポジトリーを作成するでござる。ここでは、 daisuke_cfgfiles という名前のリポジトリーを作成してみるでご ざる。


% pwd
/amd/nakano/root/volume1/nas1/git_repository/daisuke_cfgfiles
% git init --bare
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 
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 
Initialized empty Git repository in /amd/nakano/root/volume1/nas1/git_repository/daisuke_cfgfiles/
% ls -lF
total 56
-rw-r--r--  1 git  git    23 Feb 11 19:51 HEAD
-rw-r--r--  1 git  git    66 Feb 11 19:51 config
-rw-r--r--  1 git  git    73 Feb 11 19:51 description
drwxr-xr-x  2 git  git  4096 Feb 11 19:51 hooks/
drwxr-xr-x  2 git  git  4096 Feb 11 19:51 info/
drwxr-xr-x  4 git  git  4096 Feb 11 19:51 objects/
drwxr-xr-x  4 git  git  4096 Feb 11 19:51 refs/

これで、 server 側の準備はできたでござる。このあとは、別の計算機上で作 業をするでござる。 server ではない別の計算機で daisuke_cfgfiles のためのファイルを作り、それを commit して みるでござる。また、 git server は abc.astro.ncu.edu.twとし、 git server で動いている ssh server は port 54321 で通信しているとする でござる。

計算機 client 1 で、まず空のリポジトリーを作成するでござる。


% pwd
/home/daisuke
% mkdir -p share/daisuke_cfgfiles
% cd share/daisuke_cfgfiles
% pwd
/home/daisuke/share/daisuke_cfgfiles
% git init
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 
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 
Initialized empty Git repository in /home/daisuke/share/daisuke_cfgfiles/.git/
% ls -alF
total 24
drwxr-xr-x  3 daisuke  taiwan  512 Feb 11 19:54 ./
drwxr-xr-x  3 daisuke  taiwan  512 Feb 11 19:53 ../
drwxr-xr-x  6 daisuke  taiwan  512 Feb 11 19:54 .git/

README.md ファイルを作り、それをリポジトリーに追加してみるでござる。


% vi README.md
% cat README.md 
# My own repository for configuration files

This is a repository for my own configuration files, such as .cshrc, .emacs,
and .Xresources. This repository was created on 11 February 2025.
% git status
On branch master

No commits yet

Untracked files:
  (use "git add ..." to include in what will be committed)
        README.md

nothing added to commit but untracked files present (use "git add" to track)
% git add README.md
% git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached ..." to unstage)
        new file:   README.md

% git commit -m 'adding README.md'
[master (root-commit) 8bb6c6f] adding README.md
 1 file changed, 4 insertions(+)
 create mode 100644 README.md
% git remote add cfgfiles ssh://git@abc.astro.ncu.edu.tw:54321/home/git/repo/daisuke_cfgfiles
% git push cfgfiles master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 6 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 343 bytes | 343.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To ssh://abc.astro.ncu.edu.tw:54321/home/git/repo/daisuke_cfgfiles
 * [new branch]      master -> master

もう一つ、ファイルを追加してみるでござる。


% vi dot.Xresources
% cat dot.Xresources 
XTerm*background: wheat
XTerm*foreground: black
XTerm*geometry: 80x24
XTerm*font: 12x24
% git status
On branch master
Untracked files:
  (use "git add ..." to include in what will be committed)
        dot.Xresources

nothing added to commit but untracked files present (use "git add" to track)
% git add dot.Xresources
% git status
On branch master
Changes to be committed:
  (use "git restore --staged ..." to unstage)
        new file:   dot.Xresources

% git commit -m 'adding dot.Xresouces'
[master f2ee93e] adding dot.Xresouces
 1 file changed, 4 insertions(+)
 create mode 100644 dot.Xresources
% git push cfgfiles master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 6 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 348 bytes | 348.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To ssh://abc.astro.ncu.edu.tw:54321/home/git/repo/daisuke_cfgfiles
   8bb6c6f..f2ee93e  master -> master

リポジトリー daisuke_cfgfiles に、 README.mddot.Xresources が追加されたので、更に別の計算機 client 2 で これらのファイルを取得してみるでござる。


% git clone ssh://git@abc.astro.ncu.edu.tw:54321/home/git/repo/daisuke_cfgfiles
Cloning into 'daisuke_cfgfiles'...
Enter passphrase for key '/home/daisuke/.ssh/id_ed25519': 
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (6/6), done.
% ls -lF
total 4
drwxr-xr-x  3 daisuke  taiwan  512 Feb 11 20:16 daisuke_cfgfiles/
% ls -lF daisuke_cfgfiles
total 8
-rw-r--r--  1 daisuke  taiwan  188 Feb 11 20:16 README.md
-rw-r--r--  1 daisuke  taiwan   88 Feb 11 20:16 dot.Xresources

この計算機 client 2 で、 dot.Xresources を変更してみるでござる。


% cd daisuke_cfgfiles
% pwd
/home/daisuke/share/daisuke_cfgfiles
% ls -lF
total 8
-rw-r--r--  1 daisuke  taiwan  188 Feb 11 20:16 README.md
-rw-r--r--  1 daisuke  taiwan   88 Feb 11 20:16 dot.Xresources
% vi dot.Xresources
% cat dot.Xresources 
!
! xterm
!
XTerm*background: wheat
XTerm*foreground: black
XTerm*geometry: 80x24
XTerm*font: 12x24

!
! xcursor
!
Xcursor.theme: Adwaita
Xcursor.size: 512
% git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git restore ..." to discard changes in working directory)
        modified:   dot.Xresources

no changes added to commit (use "git add" and/or "git commit -a")
% git add dot.Xresources
% git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged ..." to unstage)
        modified:   dot.Xresources
% git commit -m 'modifying dot.Xresources'
[master 6e224e1] modifying dot.Xresources
 1 file changed, 9 insertions(+)
% git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
% git push
Enter passphrase for key '/home/daisuke/.ssh/id_ed25519': 
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 2 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 404 bytes | 404.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To ssh://abc.astro.ncu.edu.tw:54321/home/git/repo/daisuke_cfgfiles
   f2ee93e..6e224e1  master -> master

計算機 client 2 から、もう一つ新しいファイルを追加してみるでござる。


% vi dot.emacs
% cat dot.emacs 
;
; colours
;
(set-face-foreground 'default "black")
(set-face-background 'default "AntiqueWhite")
% git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add ..." to include in what will be committed)
        dot.emacs

nothing added to commit but untracked files present (use "git add" to track)
% git add dot.emacs
% git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged ..." to unstage)
        new file:   dot.emacs

% git commit -m 'adding dot.emacs'
[master 34dbaa4] adding dot.emacs
 1 file changed, 5 insertions(+)
 create mode 100644 dot.emacs
% git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
% git push
Enter passphrase for key '/home/daisuke/.ssh/id_ed25519': 
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 2 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 384 bytes | 384.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
To ssh://abc.astro.ncu.edu.tw:54321/home/git/repo/daisuke_cfgfiles
   6e224e1..34dbaa4  master -> master

計算機 client 1 でファイルを更新してみるでござる。


% git pull ssh://git@abc.astro.ncu.edu.tw:54321/home/git/repo/daisuke_cfgfiles
From ssh://abc.astro.ncu.edu.tw:54321/home/git/repo/daisuke_cfgfiles
 * branch            HEAD       -> FETCH_HEAD
Updating f2ee93e..34dbaa4
Fast-forward
 dot.Xresources | 9 +++++++++
 dot.emacs      | 5 +++++
 2 files changed, 14 insertions(+)
 create mode 100644 dot.emacs

今度は、計算機 client 1 でファイルを編集したり追加したりしてみるでござ る。


% vi dot.emacs
% cat dot.emacs 
;
; colours
;
(set-face-foreground 'default "black")
(set-face-background 'default "AntiqueWhite")

;
; time-stamp
;
(defvar time-stamp-format "%Y/%02m/%02d %02H:%02M:%02S (%Z) %u")
(add-hook 'write-file-hooks 'time-stamp)
% git status
On branch master
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git restore ..." to discard changes in working directory)
        modified:   dot.emacs

no changes added to commit (use "git add" and/or "git commit -a")
% git add dot.emacs
% git status
On branch master
Changes to be committed:
  (use "git restore --staged ..." to unstage)
        modified:   dot.emacs

% git commit -m 'modifying dot.emacs'
[master 87da873] modifying dot.emacs
 1 file changed, 6 insertions(+)
% git push cfgfiles master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 6 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 405 bytes | 405.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
To ssh://abc.astro.ncu.edu.tw:54321/home/git/repo/daisuke_cfgfiles
   34dbaa4..87da873  master -> master
% vi dot.xinitrc
% cat dot.xinitrc 
#
# settings
#
xrandr
xrdb $HOME/.Xresources

#
# X11 clients
#
xterm -C -iconic -sb -bg wheat -fn 12x24 &
oclock -geometry -0+35 -bd yellow -hour green -minute green -jewel red -transparent &

#
# window manager
#
exec fvwm3
% git status
On branch master
Untracked files:
  (use "git add ..." to include in what will be committed)
        dot.xinitrc

nothing added to commit but untracked files present (use "git add" to track)
% git add dot.xinitrc
% git status
On branch master
Changes to be committed:
  (use "git restore --staged ..." to unstage)
        new file:   dot.xinitrc

% git commit -m 'adding dot.xinitrc'
[master 3540015] adding dot.xinitrc
 1 file changed, 16 insertions(+)
 create mode 100644 dot.xinitrc
% git push cfgfiles master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 6 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 450 bytes | 450.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
To ssh://abc.astro.ncu.edu.tw:54321/home/git/repo/daisuke_cfgfiles
   87da873..3540015  master -> master

計算機 client 2 で、ファイルを更新してみるでござる。


% git pull -r
Enter passphrase for key '/home/daisuke/.ssh/id_ed25519': 
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 6 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (6/6), 834 bytes | 34.00 KiB/s, done.
From ssh://abc.astro.ncu.edu.tw:54321/home/git/repo/daisuke_cfgfiles
   34dbaa4..3540015  master     -> origin/master
Updating 34dbaa4..3540015
Fast-forward
 dot.emacs   |  6 ++++++
 dot.xinitrc | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 dot.xinitrc
% ls -lF
total 16
-rw-r--r--  1 daisuke  taiwan  188 Feb 11 20:16 README.md
-rw-r--r--  1 daisuke  taiwan  156 Feb 11 20:24 dot.Xresources
-rw-r--r--  1 daisuke  taiwan  223 Feb 11 20:49 dot.emacs
-rw-r--r--  1 daisuke  taiwan  226 Feb 11 20:49 dot.xinitrc

参考文献



Frequently accessed files

  1. Computer___Python/20220518_0.html
  2. Computer___Network/20230726_00.html
  3. Misc___Taiwan/20240207_00.html
  4. Computer___Network/20230516_00.html
  5. Computer___FreeBSD/20220621_0.html
  6. Computer___Python/20220715_0.html
  7. Computer___Network/20230508_00.html
  8. Computer___Network/20240130_00.html
  9. Food___Taiwan/20220429_0.html
  10. Computer___NetBSD/20230119_00.html
  11. Computer___Network/20240416_00.html
  12. Computer___Python/20220410_0.html
  13. Computer___NetBSD/20220817_3.html
  14. Computer___Python/20221013_0.html
  15. Computer___TeX/20231107_00.html
  16. Computer___Debian/20210223_1.html
  17. Computer___Python/20210124_0.html
  18. Computer___NetBSD/20220818_1.html
  19. Computer___Python/20240101_00.html
  20. Computer___NetBSD/20220428_0.html
  21. Computer___NetBSD/20240101_02.html
  22. Computer___Network/20220413_1.html
  23. Misc___Japan/20240610_00.html
  24. Science___Math/20220420_0.html
  25. Computer___TeX/20230503_00.html
  26. Computer___TeX/20230726_01.html
  27. Computer___NetBSD/20220808_0.html
  28. Science___Astronomy/20220503_0.html
  29. Computer___NetBSD/20230515_00.html
  30. Computer___NetBSD/20210127_0.html


HTML file generated by Kinoshita Daisuke.