GitHubのリポジトリをローカルにClone

前回申し込んだGitHubのリポジトリをローカルにクローンする。

基本的にはgit for windowsをインストールしてgitlabのプロジェクトを操作に記載した内容でOK。
今回は既にGitLabのリポジトリへの接続環境が作成されているPC上にGitHubのリポジトリへの接続環境を構築する。
GITHUBもGITLABと同様にSSHキーを必要とするため以下に従って作成。(保存するファイルはデフォルトではなくgithub_kernel_rsaに変更)

C:\Git\usr\bin>ssh-keygen -t rsa -C 'メールアドレス'
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/tarumi/.ssh/id_rsa): /c/Users/tarumi/.ssh/github_kernel_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/tarumi/.ssh/github_kernel_rsa.
Your public key has been saved in /c/Users/tarumi/.ssh/github_kernel_rsa.pub.
The key fingerprint is:
省略
C:\Git\usr\bin>

なぜかファイル名が文字化けしていたので修正

GitHubのサイトにSSHキーを登録

GItHubのサイトの「your profile」を表示

「Edit Profile」ボタンを押す

「SSH and GPG keys」を選択し「New SSH Key」ボタンを押す

github_kernel_rsa.pubの内容を貼り付ける

C:\Git\etc\ssh\ssh_configを以下に従って編集
※この設定は複数のGITリポジトリ(GITLABとGITHUB)とアクセスするために設定する

Host gitlab
    User git
    Port 22
    HostName gitlab.com
    TCPKeepAlive yes
    identitiesonly yes
    identityFile /C/Users/tarumi/.ssh/id_rsa

Host github
    User git
    Port 22
    HostName github.com
    TCPKeepAlive yes
    identitiesonly yes
    identityFile /C/Users/tarumi/.ssh/github_kernel_rsa

github上のリポジトリをローカルにクローン

今回はC:\githubhomeディレクトリ以下にローカルリポジトリを作成していく。

通常(ssh_configの設定を使用しない)はgithubのリポジトリサイトを表示し「clone or download」ボタンを押しsshのURLを表示し

以下のコマンドでgithub上のリポジトリをローカルにクローンする。

git clone git@github.com:組織名/test.git

今回(ssh_configの設定を使用)は以下のコマンドでクローンする

git clone git@github:組織名/test.git

上記で指定したgithubはssh_configのHostに指定した値

C:\githubhome>git clone git@github:組織名/test.git
Cloning into 'test'...
Enter passphrase for key '/C/Users/tarumi/.ssh/github_kernel_rsa':
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.

リポジトリのフォルダに移動して以下のコマンドでgitへの接続ユーザーの設定を行う

C:\>cd githubhome
C:\githubhome>cd test
C:\githubhome\test>git config --local user.email 'メールアドレス'
C:\githubhome\test>git config --local user.name 'ユーザー名'
C:\githubhome\test>git config --local core.quotepath off

引数に–localを付けたときはローカルリポジトリのフォルダ内のみで有効な設定として保存される。

設定した内容はローカルリポジトリ内の.gitフォルダに保存される