LoginSignup
0
0

git addからgit pushまでのコマンド面倒じゃない?

Posted at

zshを利用している方向け。

何が面倒なのか?

日々の開発で、ファイルを変更したら以下のコマンドでpushするのが一般的です。

git add <file>
git commit -m "message"
git push origin <branch>

ただ変更をコミットするのにgit <command> ...と打ったり、3回もコマンドを実行するのは面倒!

どうやる?

oh-my-zshのgit pluginによるalias

ohmyzshgit pluginに組み込まれているaliasを利用することでここまで短縮可能です。

ga <file> # 全てのファイルの場合は gaa というaliasが存在
gcmsg "message"
gp origin <branch>

さらに短く

git-configpush.defaultcurrentを指定することで現在のブランチでpushを行います。

git config --global push.default current

そして、ここまで短縮

ga <file>
gcmsg "message"
gp # originなんていらん!

shellでfunctionを使用する

ここで紹介しているものは全てのファイルを現在のブランチでpushする場合に使えます。
私は以下のfunctionを.zshrcに入れてます。

function acp() {
  git add .
  git commit -m "$1"
  git push
}

これで1回のコマンドで済むぜ :thumbsup:

acp "add: function"

他のやり方があれば教えていただけると嬉しいです!

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