POSTD PRODUCED BY NIJIBOX

POSTD PRODUCED BY NIJIBOX

ニジボックスが運営する
エンジニアに向けた
キュレーションメディア

POSTD PRODUCED BY NIJIBOX

POSTD PRODUCED BY NIJIBOX

ニジボックスが運営する
エンジニアに向けた
キュレーションメディア

FeedlyRSSTwitterFacebook
Jonathan Suh

本記事は、原著者の許諾のもとに翻訳・掲載しております。


GitBash使1

Git Bash


Gitgit checkoutgit cogitBashBash
Git Bash~/.bashprofile~/.bashrc使
 Terminal/Bash Command-Line Shortcuts with Aliases 
&source ~/.bashprofile
# ----------------------
# Git Aliases
# ----------------------
alias ga='git add'
alias gaa='git add .'
alias gaaa='git add -A'
alias gb='git branch'
alias gbd='git branch -d '
alias gc='git commit'
alias gcm='git commit -m'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcom='git checkout master'
alias gd='git diff'
alias gda='git diff HEAD'
alias gi='git init'
alias gl='git log'
alias glg='git log --graph --oneline --decorate --all'
alias gld='git log --pretty=format:"%h %ad %s" --date=short --all'
alias gm='git merge --no-ff'
alias gp='git pull'
alias gss='git status -s'
alias gst='git stash'
alias gstl='git stash list'
alias gstp='git stash pop'
alias gstd='git stash drop'

# ----------------------
# Git Function
# ----------------------
# Git log find by commit message
function glf() { git log --all --grep="$1"; }

このエイリアスを使えば、キーストロークが減ったとすぐに実感できるでしょう。エイリアスのほとんどはGitコマンドの単純な省略です。例えば、git add assets/css/screen.cssを実行したい時は以下のように書きます。

ga assets/css/screen.css

git checkout –b を実行したい時は以下のように書きます。

gcb <branch-name>

独自にカスタマイズしたものもいくつかあります。私はgit logで使い勝手の良い組み合わせを2つ見つけましたので、それを使っています。gldは、git logのコミット履歴の詳細を一行表示にしてくれます。

$ gld
dba068d 2015-02-11 Remove stop propagation.
37372ec 2015-02-11 Remove third-party Twitter widget.js completely and replace with intent link.
7d1a5d2 2015-02-11 Uglify critical in production task.
d9bf43b 2015-02-11 Custom robots.
166b6bd 2015-02-11 Secondary page share images.
6c77889 2015-02-11 Fix share_image logic.
93df2b1 2015-02-10 Exclude topic and archives from sitemap. Change up priority.
f72ccc1 2015-02-09 Social share post include Reddit. Fix http to https.
6a42288 2015-02-11 Uglify critical in production task.
8564aba 2015-02-11 Configure robots for pages.

glggit log


mgit mergeno-offno fast-forward使

Gitlogglf使lf使
glf "commit message"

すると、次のように出力されます。

$ glf "logic"
commit 95ed7d5b6f6d168047fd8ddc86579ce09ca39394
Author: Jonathan Suh <hello@jonsuh.com>
Date:   Wed Feb 11 08:51:11 2015 -0600

    Fix share_image logic.

commit 15bbdc6001d6c95d575078cb96352943b3b321e0
Author: Jonathan Suh <hello@jonsuh.com>
Date:   Tue Sep 30 20:18:29 2014 -0500

    Navigation link is-current logic.

Git

git statusgs
alias gs='echo ""; echo "*********************************************"; echo -e "   DO NOT FORGET TO PULL BEFORE COMMITTING"; echo "*********************************************"; echo ""; git status'

gsを実行する度に、コミットを作成する前にpullすることを忘れないで済みます。

$ gs

*********************************************
   DO NOT FORGET TO PULL BEFORE COMMITTING
*********************************************

On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

これらのエイリアスと関数を使えば、何千ものキーストロークを節約し、あなたの寿命を延ばすことになるでしょう。この他にも特に役立つエイリアスや関数をご存じなら、
私とシェアしてください

監修者
監修者_古川陽介
古川陽介
株式会社リクルート プロダクト統括本部 プロダクト開発統括室 グループマネジャー 株式会社ニジボックス デベロップメント室 室長 Node.js 日本ユーザーグループ代表
複合機メーカー、ゲーム会社を経て、2016年に株式会社リクルートテクノロジーズ(現リクルート)入社。 現在はAPソリューショングループのマネジャーとしてアプリ基盤の改善や運用、各種開発支援ツールの開発、またテックリードとしてエンジニアチームの支援や育成までを担う。 2019年より株式会社ニジボックスを兼務し、室長としてエンジニア育成基盤の設計、技術指南も遂行。 Node.js 日本ユーザーグループの代表を務め、Node学園祭などを主宰。