LoginSignup
1
0

LinuxにおけるGitHubのお手軽な使い方

Posted at

キー

まず、GitHub用のSSHキーとGPGキーを作成して登録する。両者ともに専用のキーを使い、会社用と個人用などで使い分けられるようにする。

SSHキーを作成

ssh-keygen -t ed25519 -N '' -C '' -f ~/.ssh/id_ed25519_hydratlas

代替ホスト名とSSHキーの組み合わせを~/.ssh/configに追記

nano ~/.ssh/config
Host github-hyd
    HostName github.com
    IdentityFile ~/.ssh/id_ed25519_hydratlas
    User git

GPGキーを作成

GitHubが、GitHubに登録したメールアドレスを隠すためのメールアドレスを用意してくれているため、それを https://github.com/settings/emails で確認して使用する。

gpg --pinentry-mode loopback --passphrase '' --quick-gen-key \
  'hydratlas <160527126+hydratlas@users.noreply.github.com>' \
  future-default - 0

GPGキーを確認

gpg --list-secret-keys --keyid-format LONG
/home/hydratlas/.gnupg/pubring.kbx
-----------------------------
sec   ed25519/F42BDA4E5020D58E 2024-03-05 [SC]
      302B4894754005BAD5FC21C5F42BDA4E5020D58E
uid                 [  究極  ] hydratlas <160527126+hydratlas@users.noreply.github.com>
ssb   cv25519/25AD91FADDEF6786 2024-03-05 [E]

GitHubにSSHキー・GPGキーを登録

cat ~/.ssh/id_ed25519_hydratlas.pub

gpg --armor --export 302B4894754005BAD5FC21C5F42BDA4E5020D58E

表示した内容を https://github.com/settings/keys に登録する。

git clone

git clone git@github-hyd:hydratlas/tips.git

必要に応じて.gitignoreファイルを作り、除外ファイルを指定する。

git config

cd tips &&
git config user.name 'hydratlas' &&
git config user.email '160527126+hydratlas@users.noreply.github.com' &&
git config commit.gpgsign true &&
git config user.signingkey 25AD91FADDEF6786

gpg --list-secret-keys --keyid-format LONGのssb欄(cv25519/25AD91FADDEF6786)を参照する

リモート(Github)での変更をローカルに反映させる

git pull origin main

ローカルでの変更をリモート(Github)に反映させる

git add --all &&
git commit -m "" --allow-empty-message &&
git branch -M main &&
git push -u origin main

コミットメッセージはできれば書いたほうがよい。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0