🧰

【目的別】Gitコマンドのチートシート

に公開

全リモートブランチをローカルブランチに反映したい

for branch in $(git branch -r | grep -v '\\-'); do
  git branch --track "${branch#origin/}" "$branch" 2/dev/null
done

コミットには出てない、変更したはずの履歴を辿りたい

git reflog
git checkout HEAD@3
git fsck --lost-found

いくつかのコミットをまとめたい

git rebase -i HEAD~4

強制プルしたい

git reset --hard origin/ブランチ名

最新のコミットをほかのブランチ(branch_name)の末尾に加えたい(リベースしたい)

git rebase branch_name

リベースを中断したい

git rebase --abort

実行したrebaseを元に戻したい

git reflog
git reset --hard HEAD@4

直前のコミットに現在ステージングしている内容を含めたい

git commit --amend

別のブランチにpushしたい

git push origin PUSHしたいローカルブランチ名:PUSH先リモートブランチ名

Discussion