Git for Windows — Windows で Git を使う

Git for Windows をインストールする

Download for Windows のページからインストーラを入手。

インストール時の設定は基本的にデフォルトでいい。 コミット時のエディタと git pull の挙動は適当なものを選ぶ。

Select Destination Location
C:\Program Files\Git
Select Components, Select Start Menu Folder
default
Choosing the default editor used by Git
Use Visual Studio Code as Git’s default editor
Adjusting the name of the initil branch in new repositories
Override the default branch name for new repositories main
Adjusting your PATH environment
Git from the command line and also from 3rd-party software (recommended)
Choosing the SSH executable
Use bundle OpenSSH
Choose HTTPS transport backend
Use the OpenSSL library
Configuring the line ending conversion
Checkout Windows-style, commit Unix-style line ending
Configuring the terminal emulator to use with Git Bash
Use MinTTY (the default terminal of MSYS2)
Choose the default behavior of git pull
Fast-forward or merge
Choose a credential helper
Git Credential Manager
Configuring extra options
Enable file system caching
Enable symboic links
Configuring experimental options
チェックなし

グローバル設定

Windows のホームディレクトリに .gitconfig ができる。

ここに必要な設定を追加していく:

~/.gitconfig
[user]
    name = ymat2
    email = ymat2@users.noreply.github.com

[init]
    defaultBranch = main

[push]
    default = simple

[pull]
    ff = only

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

[diff]
    submodule = log

[core]
    editor = vim

これだけでもほぼ Unix と同じように使える。 実際の使い方は Git/GitHub を参照。

Git Bash

Git for Windows に同梱されている Bash エミュレーション。 Bash と基本的なコマンドが提供されている。 MSYS ベース。 パッケージ管理ツール (pacman) とビルドツールチェイン (gcc など) は付いていない。

Git Bash アプリからターミナルを開くか、 Windows Terminal のプロンプトの1つとして登録する。 起動オプションで明示的にログインシェルとして立ち上げる --login 必要がある?

posh-git

posh-git is a PowerShell module that integrates Git and PowerShell by providing Git status summary information that can be displayed in the PowerShell prompt

らしい。 PowerShell で Git を便利に使うためのモジュールっぽいが、必ずしも必要ではない。