Skip to content

Instantly share code, notes, and snippets.

@tomoima525
Last active August 29, 2015 13:57
Show Gist options
  • Save tomoima525/9639844 to your computer and use it in GitHub Desktop.
Save tomoima525/9639844 to your computer and use it in GitHub Desktop.
git,githubのコマンド チートシート ref: http://qiita.com/tomoima525/items/a3d5dd3e6546d52a5cfb
$ git status
$ git add -p 追加するものを選択
$ git add -A すべて追加
$ git reset --hard HEAD^
$ git reset --soft HEAD^
$ git rm -r --cached filename or directory 例 log/*.log
$ vi .gitignore //ignore対象ファイルを加える
$ git add .gitignore
$ git commit -m ".gitignore is now working"
$ git push origin master
$ git branch
$ git checkout ブランチ名
$ git branch -m <oldname> <newname>
$ git fetch (リモートからレポジトリ取得)
$ git status ステータスを確認
$ git checkout -b hoge -t origin/hoge (githubにあるorigin/hogeと同じ内容のブランチhogeを作る)
$git branch (ブランチがhogeになっているか確認)
$ git checkout -b new_branch (ブランチ作成)
$ git commit --allow-empty -m "make pull request" (空コミットを許可してコミット)
$ git push origin new_branch:new_branch (githubへpush)
$ git branch -d search
$ git diff インデックスとワークツリーの差分(addする前の差分)
$ git diff --cached インデックスと最新コミット(addしてからの差分)
$ git diff HEAD ワークツリーと最新コミット
$ git push origin :search
$ git filter-branch -f --index-filter 'git update-index --remove "filename"' HEAD
$ git push --force
$ git remote -v
origin https://github.com/***/***.git (fetch)
origin https://github.com/***/***.git (push)
$ git remote set-url origin [email protected]:***/***.git
$ git remote -v
origin [email protected]:***/***.git (fetch)
origin [email protected]:***/***.git (push)
$ git commit --allow-empty -m "make pull request"
$ mkdir /pub/repository/backup.git
$ cd /pub/repository/backup.git
$ git --bare init
$ cd {workdir}/
$ git push /pub/repository/backup.git master
$ git clone /pub/repository/backup.git {workdir}
$ git push origin master
origin -> もとのリポジトリ(ローカルブランチ) master->マスタブランチ
$ git remote add origin [email protected]:example/test.git
fatal: remote origin already exists.
$ git commit -a インデックスへadd,commit(git add -u -> git commitと同等)
$ git commit -v verbose
$ git commit --amend 直前のコミットをやり直す
$ git remote -v
origin [email protected]:example/test.git
$ git remote add origin2 [email protected]:example/test.git
$ git remote -v
origin [email protected]:example/test.git
origin2 [email protected]:example/test.git
# git push origin <ローカルでのブランチ名>:<githubでのブランチ名>
$ git push origin change_hoge:change_hoge
$ git merge master
$ git rm --cached hoge.txt
$ git reset HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment