@ledsun blog

無味の味は佳境に入らざればすなわち知れず

git Fork をWSLで使う

Macの頃から Fork というgitのGUIクライアントを使っています。

f:id:ledsun:20211110220851p:plain
git Forkのスクリーンショット

これをWSL上のgitリポジトリに対して使う話です。 wsl-gitという便利なツールがあります。 WSL上のgitコマンドをホストのWindows側から実行するためのラッパーです。

Usage in Fork

To make Fork use git from WSL you must have done the first optional installation step (run install.bat). Then go to the Fork preferences and select a custom git instance where you point it to the git.exe in the wslgit\bin folder (not the cmd folder!).

Fork用の設定方法まで書いてあって至れり尽くせりです。

Release Version 1.0.1 · andy-5/wslgit · GitHub からwslgit.zipをダウンロードしてきて、中に含まれるinstall.batを管理者権限で実行します。

Create 'bin' directory...
OK.

Create 'bin\git.exe' symlink...
C:\Users\led_l\Downloads\wslgit\wslgit\bin\git.exe <<===>> C:\Users\led_l\Downloads\wslgit\wslgit\cmd\wslgit.exe のシン ボリック リンクが作成されました
OK.

Create 'bin\Fork.RI' symlink...
C:\Users\led_l\Downloads\wslgit\wslgit\bin\Fork.RI <<===>> C:\Users\led_l\Downloads\wslgit\wslgit\cmd\Fork.RI のシンボリック リンクが作成されました
OK.

Create 'bin\sh.exe' symlink...
C:\Users\led_l\Downloads\wslgit\wslgit\bin\sh.exe <<===>> C:\Windows\System32\wsl.exe のシンボリック リンクが作成されま した
OK.

Create 'bin\bash.exe' symlink...
C:\Users\led_l\Downloads\wslgit\wslgit\bin\bash.exe <<===>> C:\Windows\System32\wsl.exe のシンボリック リンクが作成され ました
OK.

Installation successful!

(Optional) Add to the Windows Path environment variable:
 C:\Users\led_l\Downloads\wslgit\wslgit\cmd

続行するには何かキーを押してください . . .

こんな感じでシンボリックリンクを作るので、管理者権限が必要です。 長期的に使うと思うので、もうちょっとマシなディレクトリに展開してからinstall.batを実行するのが良いと思います。 間違ってもbinディレクトリ配下にシンボリックリンクを作るだけなので、binディレクトリごと消せば元に戻せます。

出来たbin/git.exeを使うようにForkを設定します。

f:id:ledsun:20211110222208p:plain
Forkが使うgitコマンドを設定

コミットフックでNode.jsが必要な場合

大抵は個々までの設定で動かせるはずです。 僕の場合は、コミットフックでNode.jsが必要なコマンドを動かしているため、次のようなエラーが出ます。

f:id:ledsun:20211110222503p:plain
コミットに失敗するエラー

わかりにくいエラーですが、Node.jsが必要なだけです。 WSLにNode.jsをインストールします。

ledsun@MSI:~►sudo apt install -y nodejs
[sudo] password for ledsun:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded.
Need to get 26.5 MB of archives.
After this operation, 179 MB of additional disk space will be used.
Get:1 https://deb.nodesource.com/node_17.x focal/main amd64 nodejs amd64 17.0.1-deb-1nodesource1 [26.5 MB]
Fetched 26.5 MB in 2s (11.4 MB/s)
Selecting previously unselected package nodejs.
(Reading database ... 39537 files and directories currently installed.)
Preparing to unpack .../nodejs_17.0.1-deb-1nodesource1_amd64.deb ...
Unpacking nodejs (17.0.1-deb-1nodesource1) ...
Setting up nodejs (17.0.1-deb-1nodesource1) ...
Processing triggers for man-db (2.9.1-1) ...

これでCLILinuxを使いつつ、GUIWindowsを使うという感じで、割と最強感ある開発環境が手に入ります。

wsl-gitはRustで書かれているようです。 こういうツールがgo-langでなくrustで書かれる時代になったようです。