LoginSignup
0
4

More than 5 years have passed since last update.

UbuntuのCLI上でGitを快適に使えるようにする方法

Last updated at Posted at 2018-05-27

UbuntuのCLI上でGitを快適に使えるようにする方法についてまとめます。

スクリプト

  • git-completion.bash
    Gitコマンドで補完が効くようにするスクリプト
  • git-prompt.sh
    CLI上にGitリポジトリの状態を表示するスクリプト

導入方法

  1. mkdir ~/.git_completion/コマンドを実行し、スクリプト用のディレクトリを作成します。
  2. cd ~/.git_completion/コマンドを実行し、カレントディレクトリをスクリプト用のディレクトリに移動します。
  3. git initコマンドを実行し、Gitのリポジトリとして初期化します。
  4. git config core.sparsecheckout trueコマンドを実行し、sparsecheckoutを有効化します。
  5. echo "contrib/completion/" > .git/info/sparse-checkoutコマンドを実行し、Cloneするディレクトリを指定します。
  6. git remote add origin https://github.com/git/gitコマンドを実行し、リモートブランチを追加します。
  7. git pull origin -tコマンドを実行し、タグの一覧をpullします。
  8. git checkout v$(git --version | awk '{print $3}')コマンドを実行し、インストールされているGitのバージョンに合ったタグをcheckoutします。
  9. echo "git-completion.bash" "git-prompt.sh" | xargs -n 1 bash -c 'chmod a+x contrib/completion/${0}'コマンドを実行し、スクリプトに実行権限を付与します。
  10. cdコマンドを実行し、カレントディレクトリをホームディレクトリに移動します。
  11. wget https://gist.githubusercontent.com/massongit/40620659e72f8c87ef734323443fe706/raw/e91ab87a3f6d83d24f9a9a37aa0b1519935622f4/.bashrc.patch ~/.bashrc.patchコマンドを実行し、.bashrcのパッチファイルをダウンロードします。
  12. patch ~/.bashrc ~/.bashrc.patchコマンドを実行し、ダウンロードしたパッチファイルを適用します。
  13. rm ~/.bashrc.patchコマンドを実行し、ダウンロードしたパッチファイルを削除します。
  14. source ~/.bashrcコマンドを実行し、変更を反映させます。

CLIの表示内容の設定

bash-git-completion、__git_ps1のオプションを設定して様々な情報を表示する - gnarl,技術メモ”’¥を参考に、~/.bashrcに変数を設定することで、表示内容をカスタマイズすることができます。

参考文献

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