LoginSignup
3
1

More than 1 year has passed since last update.

Git環境で独自のコマンドを登録する【zsh, bash】

Last updated at Posted at 2021-12-02

はじめに

Railsで開発するならbundle e rails (省略)とかめちゃくちゃ使用します。
私はgit pull origin feature/add-watch-modelとか当たりまえのようにタイピングしてました。

そして今更ですがaliasで独自コマンドを設定したので1人でも誰かの役にたてば良いな
と思って記事にしました。

参考記事

環境

  • shell: zsh

独自コマンド登録方法

とりあえず下記で登録できます。

 alias g='git'

でもターミナルを閉じたり分割すると使用できなくなります
なのでシェルの設定ファイルに書き込みます

シェルの設定ファイルへ書き込む

だいたいの人はbashかzshを使用していると思いますので下記のコマンドで設定ファイルを開きます

 vi ~/.zshrc  # zshの場合

 vi ~/.bashrc  # bashの場合

aliasを設定する(ちなみに私の設定内容です)
iを押してINSERTモードにします

 # aliasの設定
 alias ll='ls -l'
 alias la='ls -la'

 alias ..='cd ..'
 alias ...='cd ../..'
 alias ....='cd ../../..'

 alias g='git'
 alias gs='git status'
 alias gb='git branch'
 alias gd='git diff'
 alias gf='git fetch'
 alias gc='git commit'
 alias gch='git checkout'
 alias ga='git add'
 alias gcp='git cherry-pick'
 alias gps='git push origin $(git rev-parse --abbrev-ref HEAD)'
 alias gpl='git pull origin $(git rev-parse --abbrev-ref HEAD)'

 alias b='bundle'
 alias be='bundle exec'
 alias bi='bundle install'
 alias bo='bundle outdated'
 alias bu='bundle update'
 alias beru='bundle exec rubocop'
 alias berua='bundle exec rubocop -A'
 alias ber='bundle exec rspec'

 alias rc='bundle exec rails c'
 alias rcs='bundle exec rails c -s'
 alias rs='bundle exec rails s'
 alias rg='bundle exec rails generate'
 alias rr='bundle exec rails routes'
 alias rdb='bundle exec rails db'
 alias rmi='bundle exec rails db:migrate'
 alias rms='bundle exec rails db:migrate:status'
 alias rmr='bundle exec rails db:migrate:reset'

 alias v='code .'
 alias vs='code .'

そして:wqで保存します

最後に忘れがちなやつ

下記コマンドで設定を反映させる

 source ~/.zshrc # zshの場合

 source ~/.bashrc # bashの場合

まとめ

これで快適になりました。
とくにgit pullやgit pushはめちゃくちゃ楽になりました!
他に便利な独自コマンドがあれば教えて頂けると嬉しいです。

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