LoginSignup
42
36

More than 5 years have passed since last update.

Git オリジナルのコマンドを作成する

Last updated at Posted at 2014-05-02

git mycommandという感じでコマンドを作成したいな、というときの方法です。
git flowなどで使用されている方法なので、俺の便利コマンドを公開したいぜ、という方も是非ご参考ください。

基本としては、パスが通ったフォルダにgit-mycommandというファイルを保存しておくと、下記のように使えるようになります。

保存するファイル

git-mycommand
#!/bin/sh
echo my command!

保存先

  • Mac/Unixの方
    ~/local/bin/に保存し、chmod +x で実行権限を付与
  • Windowsの方
    C:\Users\xxx\binというフォルダを作成し、その中に配置(xxxはログインユーザー名。%UserProfile%/binともいえる)。

git flowはGitのインストールディレクトリにまんま展開するが、User配下のbinでちゃんと読み込んでくれるので、この方がきちんと分けられてすっきりする。

git configの設定を外部ファイルから読み込むスクリプトなどは結構使い出があると思う(直下にconfigファイルがあれば.git内に移動するといった簡単なスクリプトで実現可能)。

<参考>

42
36
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
42
36