目次

Gitでよく使うコマンド

通常はSourceTreeからGit操作するのだが、たまにコンソールからコマンド操作する事があるので備忘録。

Gitリポジトリの取得

cloneについては、「Gitのサブモジュールも一緒にcloneする」記事参照。

よく使うGitコマンド

リモートブランチの取得

リモートにどんなブランチがあるか調べる

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev_yoko
  remotes/origin/develop
  remotes/origin/master

チェックアウトしたいブランチが表示されていない時は、フェッチで情報取得する。

$ git fetch

ローカルブランチ名を指定して、リモートブランチをチェックアウトする。

$ git checkout -b other_branch origin/other_branch

現在の状況確認

いまのブランチや、前回のコミットと比較してどのファイルが変更されたの状況表示。

$ git status
ブランチ master
Your branch is up to date with 'origin/master'.
 
nothing to commit, working tree clean

ブランチを切り替える

ブランチを変更

$ git checkout develop
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.

インデックス(ステージ)に追加

ファイルやディレクトリをインデックスに登録

$ git add [filename]

すべての変更がある内容をインデックスに追加

$ git add -A

コミット

インデックスに追加されたファイルをコミット

$ git commit

コミットメッセージを同時に指定

$ git commit -m "[comment]"

変更されたファイルをインデックスに追加しコミット

$ git commit -a

push

リモートリポジトリに書き込む

$ git push [remote repository PATH] [branch]

pull

リモートリポジトリの変更の取り込み

$ git pull [remote repository PATH] [branch]

remote

リモートリポジトリの一覧表示

$ git remote

fetch

リモートリポジトリの最新情報を取得

$ git fetch

参考