Skip to content

Instantly share code, notes, and snippets.

@githiro
Last active April 26, 2018 02:27
Show Gist options
  • Save githiro/562ea7053cdbf150e4fc0d323b7a4532 to your computer and use it in GitHub Desktop.
Save githiro/562ea7053cdbf150e4fc0d323b7a4532 to your computer and use it in GitHub Desktop.
git: .gitignore_global settings

.gitignore_global用設定

コミット不要なファイルを管理してくれる.gitignoreだが、   プロジェクトのルートでgit initした後に自分で作成しなければならない。
.DS_Storeなど明らかにコミット不要なファイルも、git initしたタイミングでは無視対象に入っていない。   プロジェクト直下の.gitignoreに毎回必ず書くような内容はプロジェクトを横断した形で(globalで)無視して欲しいので、下記設定を行う。  

gitconfigを作成してgitignore_globalとユーザー名、メールアドレス、ショートカットを登録する

gitconfigについてはhttps://qiita.com/shionit/items/fb4a1a30538f8d335b35。 ひとまずglobalでデフォルトのユーザー名とメールアドレス登録も行ってしまう。 これで、globalの~/.gitconfigに設定内容が記載される。
プロジェクトごとに変えたい場合は、そのプロジェクトの.git/configを変更すること。 ショートカットも合わせて登録しておく。 vi ~/.gitconfig実行して以下を記載する。

[core]
	excludesfile = /Users/Macのユーザー名をここに入れる/.gitignore_global
[user]
	name = gitのユーザー名(半角英字)をここに入れる
	email = メールアドレスをここに入れる。Redmineと併用している場合はその登録アドレスと合わせる
[alias]
	cm = commit
	br = branch
	co = checkout
	st = status

参考:https://qiita.com/peccul/items/90dd469e2f72babbc106
終わったら、一応cat ~/.gitconfigして、内容が反映されているのを確認しておく。  

.gitignore_globalを編集

globalの無視リストとして~/.gitignore_globalを見に行くよう指定したので、今度はvi ~/.gitignore_globalしてそのファイルを作成する。 公式が推奨している値を入れているが、Logs and databasesはコメントアウトしている。
プロジェクトに応じて、適宜コメントアウトして使うこと。
あとから無視したいファイルが出てきた場合、チェックイン済みの場合はここに書いてもキャッシュを削除しなければそちらが優先されてしまい無視されないので注意。   git rm --cached ファイル名で削除できるので対応すること。  

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
#*.log
#*.sql
#*.sqlite

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment