Notebook

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

HTML ファイル生成日時: 2024/10/19 22:04:30.268 (台灣標準時)

GitHub の repository を git コマンドを使って操作する方法

GitHub の repository を手元の計算機に clone する

まず、 GitHub の repository のファイルをを clone して手元にある計算機 にファイルを展開するでござる。例えば、 my_github_account/pkgsrc_myownpkgs という repository を clone するには、 以下のようにすればよいでござる。


% git clone https://github.com/my_github_account/pkgsrc_myownpkgs.git
Cloning into 'pkgsrc_myownpkgs'...
fatal: unable to access 'https://github.com/my_github_account/pkgsrc_myownpkgs.git/': SSL certificate problem: unable to get local issuer certificate

なれど、 "SSL certificate problem: unable to get local issuer certificate" と怒られてしまったでござる。以下のコマンドを実行す ればよいようでござる。


% git config --global http.sslVerify false

これで、再度、 git clone を実行すれば、 repository の内容が手元の計算 機にコピーされてくるでござる。


% git clone https://github.com/my_github_account/pkgsrc_myownpkgs.git
Cloning into 'pkgsrc_myownpkgs'...
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 16 (delta 3), reused 4 (delta 1), pack-reused 0
Receiving objects: 100% (16/16), done.
Resolving deltas: 100% (3/3), done.

コピーされたディレクトリーとファイルを確認してみると、以下のようになっ ているでござる。

% ls -lF
total 8
drwxr-xr-x  3 daisuke  wheel  144 Apr 27 12:33 pkgsrc_myownpkgs/
% ls -lF pkgsrc_myownpkgs
total 16
-rw-r--r--  1 daisuke  wheel  1499 Apr 27 12:33 LICENSE
-rw-r--r--  1 daisuke  wheel   301 Apr 27 12:33 README.md

手元の計算機でファイルを編集する

手元の計算機上で、コピーしたファイルを編集してみるでござる。


% cd pkgsrc_myownpkgs
% ls -lF
total 16
-rw-r--r--  1 daisuke  wheel  1499 Apr 27 12:33 LICENSE
-rw-r--r--  1 daisuke  wheel   301 Apr 27 12:33 README.md
% cp -pi README.md README.md.orig
% ls -lF
total 24
-rw-r--r--  1 daisuke  wheel  1499 Apr 27 12:33 LICENSE
-rw-r--r--  1 daisuke  wheel   301 Apr 27 12:33 README.md
-rw-r--r--  1 daisuke  wheel   301 Apr 27 12:33 README.md.orig
% vi README.md
% diff -c README.md.orig README.md
*** README.md.orig      Thu Apr 27 12:33:00 2023
--- README.md   Thu Apr 27 12:37:00 2023
***************
*** 4,9 ****
--- 4,10 ----
  This repository is mainly for testing purpose.
  Packages for astronomy, physics, and mathematics are tested here.
  It is primarily for NetBSD operating system.
+ This repository is maintainted by Kinoshita Daisuke.
  
  ## pkgsrc
  

README.md ファイルに新たな一行が追加されたでござる。

変更を加えたファイルを GitHub の repository に反映する

まず、アカウントの設定を行うでござる。


% git config --global user.email myemail@aaa.bbb.ccc
% git config --global user.name my_github_account

そして、 repository に commit するでござる。


% git add README.md
% git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged ..." to unstage)
        modified:   README.md

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

% git commit
[main 8baf3f1] a change of README.md
 1 file changed, 1 insertion(+)
% git push
Username for 'https://github.com': my_github_account
Password for 'https://my_github_account@github.com': 
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/my_github_account/pkgsrc_myownpkgs.git/'

なれど、 password による認証は、どうも利用できないようになっているよう でござる。以下のウェブページ上の説明を読む必要があるようでござる。

password ではなく、 personal access token なるものが必要なようでござる。 以下のウェブページを参照する必要があるようでござる。

GitHub の personal access token には fine-grained personal access token と personal access token (classic) の二種類があるようでござる。 fine-grained personal access token はまだ beta 段階のようなので、 personal access token (classic) を使ってみることにしたでござる。

どんなことを許可してほしいのか選ぶようなのでござるが、 repository の内 容を修正したり、新たなファイルを追加するだけでよいなら、 "repo" を選んでおけばよいようでござる。 "Generate token" というボタンを押せば、 40 文字の token が表示されるでござ る。この token を Password を聞かれたときに打ち込めば、認証されるよう でござる。

実際に試してみると、以下のようになるでござる。


% git push
Username for 'https://github.com': my_github_account
Password for 'https://my_github_account@github.com': 
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), 367 bytes | 183.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/my_github_account/pkgsrc_myownpkgs.git
   fb4397c..8baf3f1  main -> main

この操作の後に、 GitHub の repository をウェブブラウザーで見てみると、 確かに変更が反映されていることが確認できるでござる。



Frequently accessed files

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


HTML file generated by Kinoshita Daisuke.