GitCommand - poramal/VuePractice GitHub Wiki
git --versiongit config --global user.name "ユーザー名"
git config --global user.email メールアドレスgit config --global --list# カレントディレクトリにリモートリポジトリ名のディレクトリを作成
git clone リモートリポジトリURL
# カレントディレクトリに任意のディレクトリ名を作成
git clone リモートリポジトリURL ディレクトリPATH# クローンして特定のブランチをワーキングツリーに展開(通常はmasterが展開)
git clone -b ブランチ名 リモートリポジトリURL
git clone -b ブランチ名 --single-branch リモートリポジトリURL
# origin以外のリモート名を指定してクローン
git clone -o origin以外のリモート名 リモートリポジトリURL
# ベアリポジトリ(ワーキングディレクトリを持たないリポジトリ)としてクローン
git clone --bare リモートリポジトリURL
# ミラーとしてクローン
git clone --mirror リモートリポジトリURL
# 最新の履歴だけクローン
git clone --depth 1 リモートリポジトリURL
# サブモジュールも一緒にクローン
git clone --recursive リモートリポジトリURL# 簡易
git remote
# 詳細
git remote -vgit remote add リモート名 リモートリポジトリURLgit remote set-url リモート名 新リモートリポジトリURLgit remote rename 旧リモート名 新リモート名git remote remove リモート名git branch 新規ブランチ名git checkout 既存ブランチ名git checkout -b 新規ブランチ名# ローカルブランチ確認
git branch
# リモートブランチ確認
git branch -r
# 全ブランチ確認
git branch -a
# アスタリスク(`*`)がついているブランチが現在の作業ブランチ# 通常削除
git branch -d 既存ブランチ名
# 強制削除
git branch -D 既存ブランチ名# contains オプションは、指定したコミットを含むブランチのみを表示する
git branch --contains=HEAD
# コミット指定を省略すると HEAD が指定されたとみなす
git branch --contains# ファイル単位
git add ファイル名
# 全て
git add .git commit -m "コミットコメント"# 指定したタグをリモートリポジトリに反映
git push リモート名 タグ名
# ローカルの全てのタグをリモートリポジトリへ反映
git push リモート名 --tagsgit push リモート名 :タグ名# リモートブランチの最新情報を取得
git fetch
# リモートブランチの最新情報を取得(リモートブランチの削除も同期)
git fetch -p
# 指定したリモートブランチの最新情報を取得
git fetch リモート別名 リモートブランチ名# 現在のブランチに、上流ブランチの最新の履歴をマージする
git merge FEACH_HEADgit fetch と git merge を連続で実行するショートハンド
# 現在のブランチに、指定したリモートブランチをマージする
git pull リモート別名 リモートブランチ名
# 現在のブランチに、上流ブランチの最新の履歴をマージする
git pull
# マージせずリベースする
git pull --rebase
# fast-forwardせず、必ずマージコミットを作成する
git pull --no-ff
# 現在のブランチに、上流ブランチの最新の履歴を強制マージする
git reset --hard
# 現在のブランチを1つ前のコミットに戻す
git reset --hard HEAD^# 現在のブランチの直前のコミットに対してタグを作成
git tag タグ名
# 指定したブランチの最後のコミットに対してタグを作成
git tag タグ名 ブランチ名
# タグにコメントを付ける(対話式)
git tag -a タグ名
# タグにコメントを付ける(コマンド内)
git tag -a タグ名 -m "メッセージ"git taggit tag -d タグ名git tag 新タグ名 旧タグ名
git tag -d 旧タグ名git tag タグ名 コミットIDgit status -s# ファイルの変更履歴
git log -p ファイル名
# フォルダの変更履歴
git log -p フォルダ名git diffgit diff ブランチ名A ブランチ名B ファイル名git diff ブランチ名A:ファイル名A ブランチ名B:ファイル名Bgit log --oneline --decorate --graph --branches --tags --remotes
# --oneline: 1commit 1行のみログ表示
# --decorate: branch名、tag名などの別名を表示
# --graph: revision graphを表示
# --branches: 他のbranchのlogも表示
# --tags: tagを表示
# --remotes: remote branchなどを表示vscode拡張:Git historyを入れるとよい?
git blame ファイル名vscode拡張:GitLensを入れたほうが良い?
参考 : https://qiita.com/fukajun/items/41288806e4733cb9c342
git stash save
# saveは省略可# リスト表示
git stash list
# 変更内容も見たい場合
git stash list -p
# 各変更について詳細に見たい場合
git stash show "stash名"
# 実行結果
<stash名>: WIP on <stashを行ったブランチ名>: <ハッシュ> <コミットコメント>git stash apply "stash名"git stash drop "stash名"git stash pop "stash名"git clone --mirror リモートリポリジトリURLgit remote set-url リモート名 複製先リポリジトリURLgit push --mirror リモート名