Skip to content

Instantly share code, notes, and snippets.

@Milly
Forked from xyzzy-17-638/gist:1992293
Created June 13, 2012 15:30
Show Gist options
  • Save Milly/2924777 to your computer and use it in GitHub Desktop.
Save Milly/2924777 to your computer and use it in GitHub Desktop.
Gitチートシート

Gitチートシート

msysGitをインストール後、 「スタート」>「Git」>「Git Bash」を実行して Git Bash を立ち上げ、 以下のコマンドを実行することで、さまざまな作業を行えます

簡単な用語集

  • master : ローカルの master ブランチ
  • origin : GitHub上の自分の clone 元のリポジトリのこと
  • origin/master : GitHub上の自分の clone 元のリポジトリの master ブランチ
  • upstream : GitHub上のFork元のリポジトリのこと
  • upstream/master : GitHub上のFork元のリポジトリの master ブランチ

初期設定

  • upstream (Fork元) を設定する

     $ cd /c/github/xyzzy
     $ git remote add upstream https://github.com/mumurik/xyzzy.git
    
  • ユーザ名、メールアドレスを設定する

     $ cd /c/github/xyzzy
     $ git config user.name "ユーザ名"
     $ git config user.email "メールアドレス"
    
  • エディタを設定する (C:\app\xyzzy\xyzzy.exe) - ただし、この設定だと日本語が使えない :(

     $ cd /c/github/xyzzy
     $ git config core.editor "start //wait /c/app/xyzzy/xyzzycli.exe -wait"
    

日常の操作

  • 間違ったので、直前の commit を取り消したい

     $ cd /c/github/xyzzy
     $ git reset --hard HEAD^
    
  • とにかく何もかも消して、upstream/master と同じ状態に戻したい

     $ cd /c/github/xyzzy
     $ git checkout master
     $ git reset --hard upstream/master
     $ git clean -fdx
    
  • ローカルの作業コピー (master) を Fork 元 (upstream/master) に合わせる

     $ cd /c/github/xyzzy
     $ git stash
     $ git fetch upstream
     $ git rebase upstream/master master
     $ git stash pop
    
  • ローカルの作業コピー (master) を GitHub にアップロード (push) する

     $ cd /c/github/xyzzy
     $ git push origin master
    
  • master をもとに、ブランチを作る

     $ cd /c/github/xyzzy
     $ git checkout master
     $ git checkout -b ブランチ名
    
  • ブランチの切り替え

     $ cd /c/github/xyzzy
     $ git checkout ブランチ名
    
  • ローカルのブランチと master を upstream に合わせる

     $ cd /c/github/xyzzy
     $ git stash
     $ git fetch upstream
     $ git rebase upstream/master master
     $ git rebase master ブランチ名
     $ git stash pop
    
  • ローカルのブランチを GitHub に push する

     $ cd /c/github/xyzzy
     $ git push -f origin ブランチ名
    
  • ローカルのブランチ一覧を見る

     $ cd /c/github/xyzzy
     $ git branch
    
  • ローカルのブランチを消す

     $ cd /c/github/xyzzy
     $ git checkout master
     $ git branch -d ブランチ名
    
  • Pull Request 用に、コミットを 1 つにまとめて GitHub に push する

        $ cd /c/github/xyzzy
        $ git checkout ブランチ名
        $ git checkout -b まとめブランチ名
        $ git rebase -i master
	<ここで、vi が開くので、2行目以降の行頭の pick を squash に変更する>
        $ git push origin まとめブランチ名
  • GitHub にあるブランチ一覧を見る

     $ cd /c/github/xyzzy
     $ git branch -r
    
  • GitHub にあるブランチを消す

     $ cd /c/github/xyzzy
     $ git push origin :ブランチ名
    
  • タグ一覧

     $ git tag -l
    
  • タグプッシュ

     $ git push --tags
    
  • 直近のタグ名

     $ git describe --tags --dirty --abbrev=0
    
  • タグ名-タグから最新までのコミット数-g最新のコミットハッシュ値 (GitHubでのzipballの名前の後半はこれを用いている)

     $ git describe --tags --dirty --long
    
  • ログのツリー表示

     $ git log --graph --decorate --pretty=oneline --abbrev-commit
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment