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 3 years have passed since last update.

Githubの使い方

0
Posted at

三年前に書いたまま、ほったらかしにされてた記事を今回供養しようと思います。

鍵を作成する

ローカル環境にて、SSH接続に必要な鍵を作成します。

ssh-keygen -t rsa -b 4096 -C "example@example"

次にどこのファイルに保存するかを聞かれるのでフルパスで答えます。

/Users/ユーザー名/.ssh/github_rsa

パスフレーズを入力します。1Passwordなどのパスワードマネージャーを使ってパスワードを作り、それを流用しましょう。

注意点として、二回入力が必要です。

最後に、作成した鍵をssh-agentに登録します。

# ssh-agentが動いているかを確認。
eval "$(ssh-agent -s)"
> Agent pid 数字

ssh-add -K /Users/ユーザー名/.ssh/github_rsa

ssh -T git@github.com

これにより、~/.ssh/configをわざわざ作成しなくてよくなります。

先ほど作成した秘密鍵をそれに対応する公開鍵を登録したサイトに対してssh接続するときにエラーがでなくなるのです。

リモートリポジトリにプッシュする

Githubで新しいリポジトリを作成します。
この時、必ずprivateにチェックをしてください。

それではssh用のurlをoriginに設定して、リポジトリにpushしてみましょう。

git remote set-url origin git@github.com:takagimeow/example-app.git
# もしくは
git remote add origin git@github.com:takagimeow/example-app.git

git push -u origin main

これで完成です。

ターミナルを閉じるたびにssh-addコマンドを打たなきゃいけない場合

~/.ssh/configファイルを作成します。

Host github github.com
	HostName github.com
	IdentityFile ~/.ssh/github_rsa
	User git

終わったら、以下のコマンドでちゃんと通っているかを確認。

ssh -T github

git clone するときなどに何度もフルパスでリモート名を入力するのが面倒臭い場合

~/.gitconfigファイルに以下を追記します。

[url "github:"]
	InsteadOf = https://github.com/
	InsteadOf = git@github.com:

これでいちいち git@github.com:takagimeow/example-appなどと入力しなくても済みます。

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?