0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ソース管理にGit/GitHubをセットアップし、VSCodeから開発を開始するまでの流れ

Last updated at Posted at 2022-05-01

はじめに

毎回忘れて調べ直すので情報をまとめておきます。
環境は以下

Gitの準備

GitをHomebrewで管理

標準で入っているgitのバージョン確認

~ % git --version
git version 2.32.0 (Apple Git-132)

Homebrewでgitを入れ直す

~ % git --version
git version 2.36.0

gitコマンドの設定

名前、メールアドレス、デフォルトエディター(今回はVSCODEを指定します)を設定。デフォルトエディターは設定しなくとも動作します。

~ % git config --global user.name '名前'
~ % git config --global user.email 'メールアドレス'
~ % git config --global core.editor 'code --wait'

これで準備完了したので、最低限の動作確認(初期化してファイルが存在するかを確認)

~ % mkdir sample
~ % cd sample
sample % git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint: 	git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint: 	git branch -m <name>
Initialized empty Git repository in sample/.git/
sample % ls -l .git
HEAD		config		description	hooks		info		objects		sample % cd ..
~ % rm -r sample
~ % 

GitHubのセットアップ

GitHubにアカウントを作成

https://github.com/ にアクセスして、ユーザ名、メールアドレス、パスワードを入力すると、いくつか質問されるため、回答をして作成が完了すると、メールアドレスにメールが到着するので、認証(Verify email address)すると作成できます。

sshでGitHubに接続する

sshのキーを作成(ログは古いのが残っていたので上書きしています)。よく忘れるので、パスフレーズは設定しませんでした(エンターキーのみ押せばOKです)。

 ~ % ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (~/.ssh/id_rsa): 
~/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in ~/.ssh/id_rsa
Your public key has been saved in ~/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:xxxxxxxxxxxx hostname.local
The key's randomart image is:
+---[RSA 3072]----+
+----[SHA256]-----+

公開鍵をクリップボードにコピー

cat ~/.ssh/id_rsa.pub | pbcopy

GitHubに設定

  1. GitHubに接続
  2. 右上のアイコンをドロップダウンしてSettingsを選択
  3. 左ペインのSSH and GPG keysを選択
  4. New SSH keyを選択
  5. Tileにsshkey20000101など分かりやすいラベルを入れて、Keyにペーストする
  6. Add SSH keyを選択して終了

SSHで接続してみる

~ % ssh -T git@github.com       
Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
~ % 

GitHubにリポジトリを作成する

ローカルに環境を作ってからGitHubに上げる方法でもできるが、一通りの資材が作られるため、GitHub側でリポジトリを作成する

  1. GitHubのトップからCreate repositoryを選択
  2. Repository nameにリポジトリ名を入れる
  3. Public(公開)もしくはPrivate(非公開)を選択.無料プランでも非公開が可能となりました。
  4. Add a REAME fileにチェックを入れる
  5. Add .gitignoreで利用する言語を入れる(不要な資材をGitHubに上げないようにできます)
  6. 非公開を選択しているので、ライセンスなしで一旦作成。ライセンスはこちらが参考になります。
  7. 作成するとリポジトリのトップが表示されます
  8. Codeを展開してSSHを選択します。
  9. 表示されたコードをクリップボードにコピーします

VSCodeから開く

GitHubで作成したリポジトリをvscodeから開いて開発を開始します。

  1. vscodeを起動
  2. Gitリポジトリのクローン…を選択
  3. 画面上部中央にリポジトリURLを指定するか、リポジトリソースを選択しますと表示されたところへ先ほどの情報をペーストします
  4. 格納先のフォルダを選択します。
  5. ウィンドウを開きREADME.md,.gitignoreが作成できていれば完了

ここまでで、GitHubとローカルを接続してvscodeからの開発が可能な状態になります。

続きは別途です

参考にしたサイト

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?