LoginSignup
1
3

More than 5 years have passed since last update.

VisualStudio2017からSSHでGitHubに接続する方法

Last updated at Posted at 2018-12-05

はじめに

タイトル通りです。
sshでのpushはVisualStudioのIDEで可能です。
sshでのcloneはVisualStudioのIDEからできないので、httpsでクローンしてからconfigを修正します。
cloneできない記事

前提

OS:Windows8.1(10でも可)
IDE:Visual Studio 2017 Community
GitHub:Public repository

GIT:git version 2.19.1.windows.1(最新じゃなくても可)
 インストール方法(2.18.0なので設定項目はちょっと違うかも)
 GitBashで公開鍵を作成するためにインストールします。
 VisualStudio2017はデフォルトでGitHubとの接続機能があるので、
 httpsで接続する場合は「Git for Windows」は不要のようです。

SSH:GitBashで公開鍵を作成します。ssh機能のインストールは不要です。
 設定方法(OSは新しくても可)

push手順

GitHubでリポジトリ作成

image.png

VisualStudioでリポジトリ作成

ローカルリポジトリを作成してから、リモートの設定を行います。
image.png

連携

作成したリポジトリをダブルクリックして、設定ボタンをクリックします。
image.png

リポジトリの設定をクリックします。
image.png

リモート 追加をクリックします。
image.png

名前にorigin フェッチ/プッシュにgithubのsshをコピーし保存をクリックします。
image.png

ホームに戻ってGitHubとの連携を確認します。
image.png

新規プロジェクト作成

新しいGitリポジトリの作成は外します。(ローカルGitリポジトリ作成をここで行ってもよいです。)
image.png

Hello Worldをpush

全てをコミットします。
image.png

passphraseを入力し、プッシュします。
passphrase入力の省略については調査中です。
image.png

GitHubで確認

image.png
image.png

clone手順

GitHub Extension for Visual Studioのインストール

VisualStudio拡張機能をインストールし、GitHubと連携します。
URL
image.png
Downloadをクリックし、ファイルをダブルクリックする。

clone

チームエクスプローラーにgithubが追加されるので、Connectをクリックします。
image.png

サインインします。
image.png

clone対象を選びます。
image.png
image.png

configの修正

httpsでクローンされるので、プロトコルをsshに変更します。
.git/configファイルをEditor開き、以下を修正します。

修正前

[remote "origin"]
    url = https://github.com/hy-since-2001/VS2017Cooperation.git

修正後

[remote "origin"]
    url = git@github.com:hy-since-2001/VS2017Cooperation.git

※設定でも変更できます。
image.png
image.png
image.png

1
3
1

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
3