Open12
Gitコマンド一覧

リモートブランチをローカルにチェックアウト
// リモートリポジトリのデータを取得
git fetch origin <ブランチ名>
// ブランチ切り替え
git checkout <ブランチ名>

過去コミットの状態まで戻す(コミットの履歴は残さない)
$ git reset --hard <コミットハッシュ>
特定のコミットの打ち消し(履歴は残す)
$ git revert <打ち消したいコミット>

git 管理対象から除外
ファイルを残したまま除外する
// ファイル単位で除外する
git rm --cached <除外ファイル>
// ディレクトリごと除外する
git rm --cached -r <除外ディレクトリ>

現在のローカルブランチをリモートにプッシュ
git push origin HEAD

特定のファイルを特定のコミットの状態に戻したい場合
$ git checkout コミットハッシュ ファイル名
編集中の特定のファイルをheadの状態に戻したい
$ git checkout ファイル名

リモートのリポジトリURL確認
$ git remote -v

ローカルのディレクトリ名を指定してgit clone
$ git clone git@github.com:<user>/<repos_name>.git <ディレクトリ名>

リモートリポジトリのURL変更
ローカルにcloneしてきたコードを別のリポジトリにpushするときなどに。
$ git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

別のブランチから特定ファイルを現在のブランチに取り込む
git checkout <取り込み元のブランチ名> <取り込むファイル名>

ローカルブランチ名の変更
git branch -m <古いブランチ名> <新しいブランチ名>
//カレントブランチを変更する場合
git branch -m <新しいブランチ名>

削除されたリモートブランチをローカルから参照しないように履歴削除
git remote prune origin