Windows10でGitを使う備忘録1

目次  

Gitインストール

Git for Windowsをインストールする。

2019/06/15時点ではバージョン2.22.0。

https://gitforwindows.org

インストーラーのオプションは全てデフォルトのまま。

コマンドプロンプトからgitコマンドでバージョン表示ができるか確認。 

C:\Users\Shiragishi>git --version
git version 2.22.0.windows.1
GitHubアカウント作成

GitHub公式サイトでSign upからアカウントを新規作成。

https://github.com

Repositoriesタブを開き、右側のNewボタンをクリック。

f:id:shiragishi:20190616004205p:plain

リポジトリ名、公開範囲などを設定する。

2019年1月7日以降、無料ユーザーでもプライベートリポジトリを選択できるようになった。

f:id:shiragishi:20190616004147p:plain

Create repositoryボタンをクリックして完了。

GitHubSSH接続する

GitHubへ接続するための秘密鍵と公開鍵を作成する。

Windows上で、適当なフォルダ内で右クリック→Git Bash Hereを選択してGit Bashを起動。

$ ssh-keygen -t rsa -b 4096 -C "hoge@piyo.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Shiragishi/.ssh/id_rsa):
Created directory '/c/Users/Shiragishi/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

鍵はGit Bashを開いた場所ではなく、Git Bashのホームディレクトリの.sshフォルダ配下に作られる(デフォルトではC:\Users\ユーザー名\.ssh)。

.sshフォルダは自動生成される。

id_rsa.pubを適当なテキストエディタで開き中身をコピー。

GitHubのSettingsからSSH and GPG keysを開き、New SSH Keyボタンをクリック。

タイトルを入力して、公開鍵の中身を貼り付ける。

Git Bash上で以下の通り入力して、Hiが表示されたらGitHubとの接続ができている。

$ ssh -T git@github.com
The authenticity of host 'github.com (52.69.186.44)' can't be established.
RSA key fingerprint is SHA256:nXXXXXXXXXX.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,52.69.186.44' (RSA) to the list of known hosts.
Enter passphrase for key '/c/Users/Shiragishi/.ssh/id_rsa':
Hi shiragishi! You've successfully authenticated, but GitHub does not provide shell access.
参考リンク