LoginSignup
2
0

More than 1 year has passed since last update.

Git + GithubをMacでの使い方

Last updated at Posted at 2022-03-16

GitHubでhttpsのパスワード認証が廃止された様でMacのターミナルにてコマンドにての操作を順を追って記載してみました。
GitHubに当方のアカウントshinsaku-jazzbass上にtest及びprivate_gitと言う、2つのリポジトリ作成して、それぞれに対応するMacローカルに、test及びprivate_gitと言う秘密キーを生成。

cd ~/.ssh
ssh-keygen -f ~/.ssh/test
ssh-keygen -f ~/.ssh/private_git
コマンドls -alにて作成確認

-rw-------   1 aaa  staff  1876  3 16 13:32 test
-rw-r--r--   1 aaa  staff   401  3 16 13:32 test.pub
pbcopy < ~/.ssh/test.pub
-rw-------   1 aaa  staff  1876  3 16 13:32 private_git
-rw-r--r--   1 aaa  staff   401  3 16 13:32 private_git.pub
pbcopy < ~/.ssh/private_git.pub

GitHub上に生成したキー中味をコピーしてそれぞれのリポジトリのdeploy keyとして登録保存する。
スクリーンショット 2022-03-16 15.25.44.png
SettingsのDeploy Keys選択、Add deploy keyボタンにて追加。
スクリーンショット 2022-03-16 15.25.55.png
スクリーンショット 2022-03-16 15.30.40.png

vim ~/.ssh/config参照下さい。以下のように編集保存。

Host github-test
  User git
  Port 22
  HostName github.com
  IdentityFile ~/.ssh/test
  TCPKeepAlive yes
  IdentitiesOnly yes

Host github-private_git
  User git
  Port 22
  HostName github.com
  IdentityFile ~/.ssh/private_git
  TCPKeepAlive yes
  IdentitiesOnly yes

上記の設定をGitHubに対して下記コマンドにて確認してする。
ssh -T git@github-test
及び
ssh -T git@github-private_git
更にそれぞれのリポジトリをローカルにcloneとしてディレクトリを生成し、そのディレクトリ内にてコマンドによる操作を行う。下記例参照。
アカウント:shinsaku-jazzbassに
~/.ssh/configでのHost名github-test、github-private_git秘密キー.gitを指定してcloneを作成。

git clone git@github-test:shinsaku-jazzbass/test.git
git clone git@github-private_git:shinsaku-jazzbass/private_git.git

これにて各ディレクトリ移動にてgitコマンド操作可能となります。

2
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
2
0