MacOs, LinuxでのGitコマンド


  • gitのバージョンをチェック

    
    $ git --version
    
  • gitのユーザー設定

    
    $ git config --global user.name "[ユーザー名]"
    $ git config --global user.email "[アドレス]"
    
  • gitの出力をカラーリング

    
    $ git config --global color.ui auto
    
  • gitコマンドのエイリアスを設定

    
    $ git config --global alias.[エイリアス] [コマンド]
    
  • ローカルリポジトリの作成

    
    $ git init
    
  • ファイルの変更をコミットする


$ git add [ファイル名]
$ git commit -m "[コミットメッセージ]"

# インデックスのバリエーション
$ git add .   # gitが管理する全てのファイルをインデックス
$ git add -u  # 最新のコミットから変更があったもの全てインデックス
  • 現在のブランチとインデックスの状態を確認

$ git status

# 現在のブランチを表示
On branch master

# インデックスしていない変更がある場合
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

    modified:   sample.txt

no changes added to commit (use "git add" and/or "git commit -a")

# インデックスしているがコミットしていない変更がある場合
Changes to be committed:
  (use "git rm --cached ..." to unstage)

    new file:   sample.txt

# 最新のコミット以後変更がない場合
nothing to commit, working directory clean
  • ファイルの編集履歴を確認
    
    $ git log

  • リモートリポジトリをローカル環境にクローン
    
    $ git clone [リモートリポジトリのURL] [ディレクトリ名]

  • リモートリポジトリからローカルにプル
    
    $ git pull orgin master