0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Git】aliasの設定方法

0
Posted at

Git aliasの設定方法

開発するたびに使用するコマンドなので、簡単に実行できるようにaliasを設定した。

動作確認環境

項目 バージョン
OS macOS 26.1
Git 2.39.5 (Apple Git-154)
シェル zsh 5.9

aliasとは

特定の文字を入力することでコマンドを実行できるようにする設定のこと。
gitでブランチを切り替えるコマンド「checkout」は毎回8文字入力する必要があるが、aliasを使用することで「co」の2文字で実行することができるようになる。

設定するファイル

設定方法は2通りある。

1. .gitconfigファイルを編集する

編集するファイルによってaliasが設定される範囲が異なる。

設定が反映される範囲 設定ファイルの場所
システム全体 /etc/gitconfig
ユーザー ~/.gitconfig もしくは ~/.config/git/config
リポジトリ リポジトリルートディレクトリ/.git/config

2. git configコマンドを使用する

git config --[設定を反映する範囲] --edit
設定が反映される範囲 コマンド
システム全体 git config --system --edit
ユーザー git config --global --edit
リポジトリ git config --local --edit

記述方法

例)「checkout」コマンドを「co」で実行するように設定

[alias]
    co = checkout

確認方法

git config --global --list

注意
設定内容を確認するときに「--global」で指定するのは自分が設定した設定範囲にすること

以下のように表示されれば設定完了

alias.co=checkout

開発環境は自分の開発しやすいようにカスタマイズして快適な開発ライフにしたいですね。

0
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?