LoginSignup
3
3

More than 1 year has passed since last update.

git branch と毎回打つのはめんどくさい

Posted at

背景

cuiでgitを使っていて、git branch だのgit checkout だのをしょっちゅう手打ちすることに気づきました。
gitコマンドは wordleではないので、最初の数文字だけでわかってほしいです。

つまり、

git br

とかでbranchを確認したいのです。

結論

gitリポジトリ内でこれを叩きます。

$ git config alias.br branch

すると以下ができるようになります。

$ git br
  aaa
  bbb
* master

何が起きたのか

.gitディレクトリ内部のconfigが更新されています

$ cd .git
$ ls
COMMIT_EDITMSG	hooks		objects
HEAD		index		refs
config		info
description	logs
$cat config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[alias]
	br = branch

[alias]に br = branch という記述が追加されているのがわかります。

試しにここで、もうひとつエイリアスを追加してみます。

$git config alias.co checkout
$cat config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[alias]
	br = branch
	co = checkout

記述が増えました。

globalに設定する方法

globalオプションをつければ、適用範囲をリポジトリ単位からユーザー単位に広げることができます

$ git config --global alias.br branch

この場合は、ホームディレクトリ直下にある.gitconfigが更新されます。

$ cd ~
$ cat .gitconfig
[user]
	email = hogehoge@mail
	name = hoge
[alias]
	br = branch

参考

Git の基本 - Git エイリアス
git configの適用範囲

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