Gitについて分からない方は以下の記事も合わせて読んでください。
あわせて読みたい


Gitとは?使う3つのメリット【超初心者向け】
Gitとはソースコードのバージョン管理ができるツールになります。Gitを使用することで以下の利点があります。 開発者間の共同作業を柔軟に対応できる。更新履歴を記録し…
目次
Gitコマンド一覧
| リポジトリに新規作成する | git init [option] |
| Gitの設定確認/変更する | git config [option] |
| ステージエリアに追加する | git add [option] [path] |
| ステージエリアから削除する | git rm [option] [path] |
| Gitに登録(コミット)する | git commit [option] [path] |
| コミットを取り消す | git reset [option] [commit_id] git restore [option] [commit_id] |
| 現在の状態を確認する | git status [option] |
| 編集した場所を確認する | git diff [option] |
| ログを確認する | git log [option] |
| リモートリポジトリから現在のブランチに取り込む | git pull [option] [repository] |
| ブランチの一覧表示/作成/削除する | git branch [option] |
| ブランチを切り替える | git checkout [option] [branch] git switch [option] [branch] |
| ブランチをマージする | git merge [option] [branch] |
| 更新履歴を綺麗にしながらマージする | git rebase [option] [branch] |
| ローカルブランチのデータをリモートブランチに送る | git push [option] [remote] [branch] |
コマンドの使用例
リポジトリに新規作成する
$ git init [option]
$ # 例
$ git init
$ ls -al
total 12
drwxr-xr-x 3 root root 4096 Oct 17 13:33 .
drwxr-xr-x 4 root root 4096 Oct 17 13:33 ..
drwxr-xr-x 7 root root 4096 Oct 17 13:33 .gitGitの設定確認/変更する
$ git config [option]
$ # 例
$ # ユーザー名の設定
$ git config --global user.name tekkubu
$ # メールアドレスの設定
$ git config --global user.email tekkubu@example.com
$ # 出力の色分け
$ git config --global color.ui true
$ # 設定の一覧表示
$ git config --global --list
user.name=tekkubu
user.email=tekkubu@example.com
color.ui=trueステージエリアに追加する
$ git add [option] [path]
$ # 例
$ # カレントディレクトリ配下のファイル、ディレクトリを追加
$ git add .ステージエリアから削除する
$ git rm [option] [path]
$ # 例
$ # カレントディレクトリ配下のファイル、ディレクトリを削除
$ git rm .Gitに登録(コミット)する
$ git commit [option] [path]
$ # 例
$ "Add main.py"のメッセージ付きコミット
$ git commit -m "Add main.py"コミットを取り消す
$ git reset [option] [commit_id]
$ # 例
$ # 直前のコミットを取り消す(ファイルはステージに残る)
$ git reset --soft HEAD^
$ # 直前のコミットとステージを取り消す(ファイルは作業ディレクトリに残る)
$ git reset --mixed HEAD^
$ # 直前のコミットまで全部削除(作業ディレクトリにも残らない)
$ git reset --hard HEAD^現在の状態を確認する
$ git status [option]
$ # 例
$ git status編集した場所を確認する
$ git diff [option]
$ # 例
$ 作業ディレクトリの編集ファイルを確認
$ git diff
$ ステージングエリアの編集ファイルを確認
$ git diff --cached
$ コミットした後の編集ファイルを確認
$ git diff -r [commit_id]ログを確認する
$ git log [option]
$ # 例
$ git log
$ # logを簡潔にまとめて表示する
$ git log --onelineリモートリポジトリから現在のブランチに取り込む
$ git pull [option] [repository]
$ # 例
$ git pullブランチの一覧表示/作成/削除する
$ git branch [option]
$ # 例
$ # branchの一覧表示
$ git branch
$ # branch「dev」を作成する
$ git branch dev
$ # branch「dev」を削除する
$ git branch -d devブランチを切り替える
$ git checkout [option] [branch]
$ # 例
$ git checkout devブランチをマージする
$ git merge [option] [branch]
$ # 例
$ # branch「dev」を「master」にマージする
$ git checkout master
$ git merge dev更新履歴を綺麗にしながらマージする
$ git rebase [option] [branch]
$ # 例
$ # branch「dev」を「master」に更新履歴ごとマージする
$ git checkout master
$ git rebase devローカルブランチのデータをリモートブランチに送る
$ git push [option] [remote] [branch]
$ # 例
$ branch「dev」をremote repositoryに送る
$ git push origin dev\ より詳しく知りたい方はこちらの本がおすすめです /
¥2,299 (2022/10/27 01:32時点 | Amazon調べ)
¥2,200 (2022/10/27 01:30時点 | Amazon調べ)








