--- lang: ja-jp breaks: true --- # git コマンド集 2021-05-01 ```shell= $ git config --global user.email "you@example.com" $ git config --global user.name "Your Name" ``` ```shell= $ git init $ git add . $ git commit -m 'Initial commit' ``` #### コミット履歴を表示 ```shell= $ git log ``` #### 最新のコミットコメントを取得 ```shell= git log -1 --pretty=format:"%s" ``` ```shell= $ git remote add origin https://github.com/XXXX/XXXXXX.git $ git push -u origin master ``` ※origin: デフォルトのリポジトリの場所(URL)の別名 ※master: デフォルトのブランチの名前。メインのブランチ ```shell= $ git clone https://github.com/XXXX/XXXXXX.git ``` ```shell= $ git status ``` ```shell= $ git diff <ファイル名> ``` ```shell= $ git commit -m "commit reason message." ``` ##### リモートから変更を取得する ```shell= $ git pull ``` ### create a new repository on the command line ```shell= $ echo "# `basename \`pwd\``" >> README.md $ git init $ git add README.md $ git commit -m "first commit" $ git branch -M main $ git remote add origin https://github.com/xxxx/WebAppTEST.git $ git push -u origin main ``` ### push an existing repository from the command line ```shell= $ git remote add origin https://github.com/xxxx/WebAppTEST.git $ git branch -M main $ git push -u origin main ``` #### コミット済みのものを管理対象から除外 ```shell= $ git rm --cached [ファイル名] $ git rm -r --cached [フォルダ名] ``` :::warning :exclamation: ※--cached オプションを付けることにより、ファイルを残したまま管理対象から外すことができる。 ::: ## ブランチ操作 #### 現在のリポジトリにあるブラントを表示 ```shell= git branch ``` #### 全てのブランチを表示 ```shell= git branch -a ``` #### リモートブランチを表示 ```shell= git branch -r ``` #### ブランチの切り替え ```shell= git checkout [ブランチ名] ``` #### ブランチの作成 ```shell= git branch [作成するブランチ名] [派生元ブランチ名] ``` :::info ブランチの作成と切り替えを一度に行う場合は以下のようにする ```shell= git branch -b [作成するブランチ名] [派生元ブランチ名] ``` ::: :::info リモートリポジトリからローカルリポジトリを作成する。 ```shell= git branch 2023-10-21_002 remotes/origin/main ``` ::: #### ブランチ名の変更 ```shell= git branch -m [変更元ブランチ名] [変更先ブランチ名] ``` #### ブランチの削除 ```shell= git branch -D [ブランチ名] ``` #### 変更の取り消し * ファイルを取り消す ```shell= git checkout -- [ファイル名] ``` * ディレクトリごと取り消す ```shell= git checkout -- [ディレクトリ名] ``` * 全変更を取り消す ```shell= git checkout -- . ``` #### フェッチ * 全てのリモートからフェッチする ```shell= git fetch --all ``` * 指定したリモートからフェッチする ```shell= git fetch origin ``` #### プッシュ * ローカルに作成したブランチをリモートにも作成する ```shell= git push -u origin 2023-10-21_005 ``` :::info 「-u」は「–set-upstream」と同じ意味 ::: ## その他 #### ユーザ名・メールアドレスを取得 ```shell= git config user.name ``` ```shell= git config --global user.name ``` ```shell= git config user.email ``` ```shell= git config --global user.email ``` #### ユーザ名・メールアドレスを削除 ```shell= git config --global --unset user.name git config --global --unset user.email ``` ```shell= git config --local --unset user.name git config --local --unset user.email ``` #### すべてのグローバル設定を表示する ```shell= git config --global --list ``` :::info 設定情報のレベル * `--local`: 現在のリポジトリのみに適用されます(デフォルト)。 * `--global`: 現在のユーザーのすべてのリポジトリに適用されます 。 * `--system`: システム上のすべてのユーザーとリポジトリに適用されます 。 ::: #### 現在のブランチ名を取得 ```shell= git branch --show-current ``` ###### tags: `git` `コマンド`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up