LoginSignup
9
5

More than 5 years have passed since last update.

毎回やってるオレ流 Git 設定

Posted at

自分のコピペ用です。(マシン(環境)が変わるごとに毎回調べたり打ち込んだりしているのが面倒なので)
Gitをコマンドで操作している方、且つ「特に何も設定してないよー」って方は同じ様に設定してみてください。結構楽になります。

動作環境: Mac ターミナル(WebStorm上)・標準搭載のGit

事前確認・準備

1:
ホームディレクトリに.bash_profile.bashrcがなければ作成しておく

# ホームディレクトリに移動
$ cd

# `.bash`で始まるファイルを確認
$ ls -a | grep ^.bash

2:
.bashrcが起動時に読み込まれる様に.bash_profileに以下コードを追加しておく
(vimか好みのエディタで編集する)

source ~/.bashrc

.bash_profile.bashrcが気になる方は → .bash_profileと.bashrcについて

常時ブランチ名表示

スクリーンショット 2018-10-05 13.04.30.png

ホームディレクトリで操作する

1:
git-prompt.sh作成

# ファイル作成
$ touch git-prompt.sh

作成したファイルに git-prompt.sh をコピペ

2:
git-completion.bash作成

# ファイル作成
$ touch git-completion.bash

作成したファイルに git-completion.bash をコピペ

3:
上ファイルを読み込むように.bashrcを編集

source ~/git-prompt.sh
source ~/git-completion.bash
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ '

4:
再読み込み

$ source .bashrc

参考:
- bashでgitのブランチ名を表示
- MacのターミナルでGitのブランチ名を表示する

Gitコマンドエイリアス作成

スクリーンショット 2018-10-05 13.06.14.png

1:
.bashrcに任意のエイリアスを追加

alias gs='git status'
alias gb='git branch'
alias gc='git checkout'
alias gl='git log'
alias gps='git push origin'
alias gpl='git pull origin'

2:
再読み込み

$ source .bashrc

参考:
- 【Mac】ターミナルで使うコマンドのエイリアスを設定する


毎回やってるなーって思ったものがあったら追記していきます。

9
5
2

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
9
5