Gitでよくやること

提供: オレッジベース
2018年12月7日 (金) 07:35時点における371 (トーク | 投稿記録)による版 (checkout)
移動先: 案内検索

リポジトリの作成

$ mkdir <DIR>
$ cd <DIR>
$ git init --bare --shared

clone

$ git clone <REPOSITORY_PATH>

pull

$ git pull

変更の確認

$ git status

add

とりあえず全部

$ git add -A

新規作成 or 変更されたもの

$ git add .

変更があったもののみ

$ git add -u

commit

$ git commit -m "<MESSAGE>"

push

$ git push <REMOTE> <BRANCH_NAME>

merge

$ git merge <BRANCH_NAME>

branch確認

$ git branch

or

$ git branch -a

checkout

特定のコミットをcheckout

$ git checkout <COMMIT_ID>

ブランチ切り替え

$ git checkout <BRANCH_NAME>

新しくブランチを持ってくる

$ git checkout -b <BRANCH_NAME> <REMOTE>/<BRANCH_NAME>

e.g

$ git checkout -b develop origen/develop

checkoutできないとき

エラー内容

fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'origin/remote-name' which can not be resolved as commit?

こうする

$ git remote show <REMOTE>
$ git remote update
$ git fetch
$ git checkout -b <BRANCH_NAME> <REMOTE>/<BRANCH_NAME>

stash

とりあえず面倒なとき

$ git stash

メッセージ付きでstash

$ git stash save "<MESSAGE>"

一覧

$ git stash list

config関連

Author

$ git config --global user.name <NAME>
$ git config --global user.email <EMAIL>

or

$ git config user.name <NAME>
$ git config user.email <EMAIL>

permission変更を無視

$ git config core.filemode false