LoginSignup
0
1

More than 5 years have passed since last update.

MacでGitをポータブルインストールする

Last updated at Posted at 2019-02-23

MacでGitをポータブルインストールする

【ぜんぶポータブル】ポータル

最終更新:2019年2月26日 .commandとdirnameを使用するよう変更

せっかくなのでMacでもGitをポータブルにします。
【ぜんぶポータブル】フォルダ構造を前提に説明していますので、適宜お使いの環境に読み替えてください。

動作確認に使用した環境

  • macOS Mojave バージョン 10.14.3(管理者権限が必要です)
  • ポータブル環境フォルダは~/OneDrive/jtHiuPortableにある

既にGitをインストールしている方へ

現在Gitを使っていない方は読み飛ばしてください。

Mac向けの主要なパッケージインストーラー等によるGitのインストール先は以下の通りです。

  • XCode command line developer tools → /usr/bin/git
  • Homebrew → /usr/local/Cellar/git/○.○.○/bin/git
  • MacPorts → /opt/local/bin/git
  • git-osx-installer → /usr/local/git/bin/git

したがって、各種Gitを既にインストールしている方が下記の手順で「git-osx-installer」をインストールしても悪影響はありません
引き続きXCode/Homebrew/MacPorts版を使用する方は、ポータブル環境構築後に/usr/local/git/uninstall.shを実行してください、完全に元通りになります。

Gitをインストールする

Gitのサイトからgit-osx-installerの.dmgをダウンロードし、その中のgit.○.○.○-intel-universal-marvericks.pkgをインストールします。
ただし、いわゆる「開発元が未確認」モノなので、Ctrlキーを押しながらアイコンをクリック→メニューの「開く」→「開く」ボタン、で起動します。普通にインストールしてください。

次に、このGitをディレクトリまるごとポータブル環境フォルダへコピーします。

Bashコマンド
cd ~/OneDrive/jtHiuPortable/apps/mac
cp -r /usr/local/git ./git

次に、環境変数HOMEとPATHを変更したBashを起動するシェルスクリプトを用意します。 1

Bashコマンド
touch setPath.command
chmod 755 setPath.command
setPath.command
#!/bin/bash
echo Portable Console is preparing environment variables.
export HOME_Backup=$HOME
export PATH_Backup=$PATH
CURRENT=$PWD
cd `dirname $0`/../..
export HOME=$PWD
cd $CURRENT
export AppsMacRoot=$HOME/apps/mac
export GitD=$AppsMacRoot/git
export PATH=$GitD/bin:$PATH
echo Portable home has located in $HOME
echo Portable applications have located in $AppsMacRoot
export PS1="Portable:\W \u\$ "
bash

これを使えば大丈夫です。

ターミナルでの実行
Mac:mac me$ ./setPath.command 
Portable Console is preparing environment variables.
Portable home has located in /Users/MyName/OneDrive/jtHiuPortable
Portable applications have located in /Users/MyName/OneDrive/jtHiuPortable/apps/mac
Portable:mac me$ which git
/Users/MyName/OneDrive/jtHiuPortable/apps/mac/git/bin/git
Portable:mac me$ git --version
git version 2.20.1

2019年2月26日追記:Finderからでもダブルクリックで起動できます。


  1. OneDrive経由でMacに新規ファイルが追加される場合、パーミッションは自動的に755になります、が、Macで新規ファイルをローカルのOneDriveフォルダへ追加する際には、いつもと同じパーミッション付与動作になります。 

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