Gitのインストールと設定
バージョン管理システムGitのインストールと基本設定を行います。
インストール
Section titled “インストール”Homebrewを使用してGitをインストール:
brew install gitユーザー情報の設定
Section titled “ユーザー情報の設定”git config --global user.name "Your Name"git config --global user.email "your.email@example.com"# デフォルトブランチ名をmainに設定git config --global init.defaultBranch main
# エディタをVSCodeに設定git config --global core.editor "code --wait"
# 日本語ファイル名のサポートgit config --global core.quotepath falseすべての設定を表示
Section titled “すべての設定を表示”git config --list設定ファイルを直接編集
Section titled “設定ファイルを直接編集”code ~/.gitconfig複数アカウントの管理
Section titled “複数アカウントの管理”複数のGitアカウントを使い分ける場合、.zshrcに以下の関数を追加:
# 個人用アカウントに切り替えfunction gitpersonal() { git config --global user.name "Your Personal Name" git config --global user.email "personal@example.com" echo "Switched to personal Git account"}
# 仕事用アカウントに切り替えfunction gitwork() { git config --global user.name "Your Work Name" git config --global user.email "work@company.com" echo "Switched to work Git account"}使用方法:
# 個人用に切り替えgitpersonal
# 仕事用に切り替えgitwork便利なエイリアス
Section titled “便利なエイリアス”.gitconfigに追加できる便利なエイリアス:
[alias] st = status co = checkout br = branch ci = commit lg = log --oneline --graph --decorateSSHキーの設定
Section titled “SSHキーの設定”GitHubやGitLabでSSHを使用する場合:
# SSHキーの生成ssh-keygen -t ed25519 -C "your.email@example.com"
# SSHキーをクリップボードにコピーpbcopy < ~/.ssh/id_ed25519.pub