4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

git のトップレベルで任意シェルコマンドを実行する alias

Posted at

git プロジェクトのトップディレクトリに cd して、そこからコマンドを実行したいことは多いはず。それを簡単に実行する。

概要

引数を exec するシェルコマンドを alias 定義する。

定義方法

git の alias として以下を定義する。例えば、~/.gitconfig に次記述。

~/.gitconfig
[alias]
	exec = !sh -c 'exec "$@"' $(which sh)

使い方いろいろ

git exec make all
# => git レポジトリのどこにいようが、トップレベルで make が実行される

git exec pwd
# => トップレベルディレクトリのパスを取得できる

git exec bundle exec rails s -d
# => rails git プロジェクトのどこにいようが、サーバーをデーモンでスタート
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?