Gitのconfig設定
・ユーザー情報を設定
git config --global user.name "user_name"
git config --global user.email "user_email"
・CRLF / LFの設定(Windows)
git config --global core.autocrlf true
・CRLF / LFの設定(macOS / Linux)
git config --global core.autocrlf input
・config設定を確認
git config --global -l
git config --local -l
リモートリポジトリについて
・ローカルリポジトリをリモートリポジトリをローカルに登録
※git initでローカルリポジトリを作成する場合、登録が必要
git remote add origin <https url>/<ssh url>
・ 登録したリモートリポジトリを確認
git remote -v
・リモートリポジトリの登録を削除
※リモートリポジトリの削除ではなく、ローカルの登録を削除する
git remote rm <remote_name>
・ リモートリポジトリの登録をリネーム
git remote rename <remote_name>
リモートに変更をプッシュ
git push
・初回は-uでディフォルトupstreamを設定
git push -u origin <remote_branch>
・初回のリモートリポジトリは空ではない場合、先にpullが必要
git pull origin <remote_branch> --allow-unrelated-histories
Gitブランチについて
・ローカルのブランチを確認
git branch
・全てのローカルのブランチを確認
git branch -a
・ブランチを切り替え
git checkout <branch_name>
・ブランチを作成し、切り替え
git checkout -b <branch_name>
・ローカルのブランチを削除
git branch -d <branch_name>
・リモートのブランチを削除
git push origin --delete <branch_name>
git pullについて
git pull = git fetch + git merge
git fetch:リモートリポジトリ情報を更新
git pull:リモートリポジトリ情報を更新し、ローカルブランチに反映する
よくある使い方:
・リモートリポジトリで更新された最新情報とローカルブランチを比較
※localに反映されてない
git fetch
git diff main origin/main
・リモートリポジトリで更新された最新情報をローカルブランチに反映
git pull origin main
※おすすめ
git pull --rebase