LoginSignup
19
18

More than 5 years have passed since last update.

よく使うgitコマンド

Last updated at Posted at 2012-12-26

クローン

githubからクローン

git clone git@github.com

クローン先のディレクトリを指定する

git clone git@github.com:user/repo hoge

ブランチを指定してクローン

git clone -b hoge git@github.com:user/repo

ブランチ

ローカルブランチ一覧

git branch

リモートブランチ一覧

git branch -r

カレントブランチ切替

git checkout hoge

ローカルブランチ作成

git branch hoge

ローカルブランチ削除

git branch -d hoge

ローカルブランチをリモートにプッシュ

git push origin local-branch:remote-branch

リモートブランチ削除

git push origin :remote-branch

ローカルブランチの名前変更

git branch -m old new

コミット

コミット

git commit -m 'message' .

差分を確認する

git status

最新のソースを取得する

git pull

コミットをプッシュする

git push

チェックアウト

ローカルの変更取り消し

git checkout .

リモートブランチをチェックアウトする

git checkout -b branch origin/branch

タグをチェックアウトする

git checkout -b name refs/tags/name

特定のコミットをチェックアウトする

git checkout commit

特定のコミットをチェックアウトした状態を別ブランチにする

git checkout commit -b branch

リベース/マージ

別のブランチの変更をリベースする

git rebase hoge

別のブランチの変更をマージする

git merge hoge

特定のコミットを適用する

git cherry-pick commit

差分

差分の内容を確認する

git diff

コミットやブランチ間の差分を確認する

git diff hoge fuga

ログ

カレントブランチのログ表示

git log

別のブランチのログ表示

git log hoge

リモートブランチのログ表示

git log origin/hoge

対象ファイル表示

git log --stat

ログ検索

git log --grep hoge

管理対象

管理対象に追加

git add .

ファイルを管理対象から削除

git rm hoge

フォルダ配下を管理対象から削除

git rm -r hoge

管理対象外のファイルを確認

git clean --dry-run

管理対象外のファイルを削除

git clean -f

タグ

タグを一覧表示する

git tag

タグを付ける

git tag -a name -m 'message' commit

タグを削除

git tag -d name

タグをプッシュする

git push origin name

タグの名前変更

git tag new old
git tag -d old
git push origin :refs/tags/old
git push origin new

stash

変更を退避

git stash save

変更を適用

git stash pop

stash一覧

git stash list

stash全削除

git stash clear

その他

upstreamを設定する

git branch --set-upstream-to=origin/branch branch

originを変更する

git remote set-url origin git@github.com:org/repo
19
18
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
18