LoginSignup
3
1

【メモ】gitを使う前によくやる設定

Last updated at Posted at 2023-08-29

 gitを使う前によくやる設定を、git初心者向けにメモ。
 これらをやっておくとミスが発生しにくくなって作業がしやすい。

目次

1.意図しない変更が入らないための設定
2.利便性を上げるための設定
3.ブランチ名と作業ツリーの状態を常に表示する

意図しない変更が入らないための設定

 今どういう設定かを確認するときはgit config --listとかで確認

# パーミッションの変更をコミットに反映しない
git config --global core.filemode false

# CRLFとLFの自動変換をオフ
git config --global core.autocrlf false
git config --global user.autocrlf false

# マルチバイト文字に対する自動変換を抑制したり文字化けを抑えたりする
git config --global core.quotepath false
git config --global core.precomposeunicode true

# 大文字小文字を区別させる
git config --global core.ignorecase false

利便性を上げるための設定

# コマンドライン上の出力のカラー化
git config --global color.ui true

# git graph コマンドを作成し、カラフルなグラフで履歴を見られるようにする
git config --global alias.graph "log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short"

ブランチ名と作業ツリーの状態を常に表示する

 こんな感じになります。
ブランチ名と作業ツリーの状態を表示

 以下のgit公式リポジトリにある、Contributed Software群の中の一つを導入することで表示させます。

●導入方法

# 作業アカウントのホームに移動
$ cd ~/

# 必要なファイルをgithubから落とす (wget が無い場合は curlの-oオプション)
$ wget https://raw.github.com/git/git/master/contrib/completion/git-completion.bash --no-check-certificate
$ wget https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh --no-check-certificate

# 隠しファイルにする
$ mv git-completion.bash .git-completion.bash
$ mv git-prompt.sh .git-prompt.sh

# ファイルを読み込むように設定を追加 (vim が無い場合は vi)
$ vim .bashrc

--.bashrcに追記する内容---------------------------

if [ -f ~/.git-completion.bash ]; then
    source ~/.git-completion.bash
fi

if [ -f ~/.git-prompt.sh ]; then
    source ~/.git-prompt.sh
fi

GIT_PS1_SHOWDIRTYSTATE=true
PS1='\[\033[01;37m\][\u@\h\[\033[01;33m\] \w\[\033[01;37m\]] \[\033[01;32m\]$(__git_ps1) \n\[\033[01;34m\]\$\[\033[00m\] '

------------------------------------------------

# ターミナルにbashrcを再読み込みさせる(ターミナルの再起動でも良い)
$ source ~/.bashrc
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