1
1

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.

MacBookへのgitとGitHub環境準備

Last updated at Posted at 2022-01-16

初めてMacBookにGitHubを使う環境をセットアップしたのでメモ。

前提

  • 作業環境はMacBook Pro(Monterey 12.1)
  • Homebrew は Homebrew インストール で書いた通りにインストール済み
  • GitHub には GitHub アカウント新規作成済み。

Macbookにgitインストール

Homebrew が既にインストールされていれば、下記実行でOK。
% brew install git

gitのバージョンを確認しておく。

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

git初期設定

  • Git のユーザ名を設定する
    % git config --global user.name "<my name>"

  • Git で使うメールアドレスを設定する
    % git config --global user.email account@example.com

  • Git で使うエディタを設定する
    % git config --global core.editor vim
    emacs派の人はここでemacsを指定すれば良いらしい。

これらを実行すると、
% ~/.gitconfig
というファイルが生まれて、追加されていく。
もしもMacbookをクリーンインストール等した場合は、この .gitconfig をバックアップしておき、配置すれば上記のコマンド実行しなくても復旧できる。

.gitconfig を移動

移動せずそのまま使ってもいいが、 ~/.config/ の下に設定ファイルを置く構成が流行り(?)らしいので、ディレクトリ用意してそちらに移動して使ってみる。

% mkdir -p ~/.config/git
% mv ~/.gitconfig ~/.config/git/config

これで設定ファイル移動は終わり。

Gitで扱うファイル置き場を用意

% mkdir ~/dev
% cd ~/dev

今回は ~/dev というディレクトリ以下にGitHubで扱うローカルディレクトリとした。

GitHub にレポジトリを用意する

今回は師匠に用意してもらったので割愛。

GitHub 2段階認証のトークン生成

今回はこちらのページを参考にさせていただきました。
@n_morioka様の記事Personal access tokens

* GiHub Personal access tokens

git cloneする

% cd ~/dev
% git clone https://github.com/<ユーザ名>/<用意されたレポジトリ名>
Username for 'https://github.com': <自分のgithubユーザ名>
Password for 'https://<自分のgithubユーザ名>@github.com': (Personal access tokensで生成したトークンをコピペ)


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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?