0
0

gitの使い方とコマンド一覧

Last updated at Posted at 2023-11-10

gitの大まかな流れ

  1. リポジトリをコピー(clone)
  2. ブランチ(update-readme)を作成
  3. README.mdを更新しコミット
  4. ローカルリポをリモートリポに反映する(push)
  5. update-readmeブランチをmainブランチにマージする
  6. リモートリポをローカルリポに反映する(pull)
  7. 不要なブランチを削除する

コマンド一覧

ブランチ情報の確認

git branch

ブランチの新規作成

git branch {branch name}

ブランチの切り替え

git checkout {branch name}

ブランチに変更内容があるか確認

git status

ローカルリポがどのリモートリポと紐付いてるか調べる
originがリファレンス名となっている

git remote -v

origin	git@gitlab.com:gitroom/djangoproject.git (fetch)
origin	git@gitlab.com:gitroom/djangoproject.git (push)

変更したファイルをステージングエリアに追加する

# 個別
git add {file name}

# すべて
git add .

ステージングエリアの内容をコミットする

git commit -m "{commit message}"

コミット履歴の表示
HEADは今いるリポジトリ
originはリモートリポジトリの状態

git log

commit aaaaaaaaaaa (HEAD -> update-readme)
Author: user <mail@mail.com>
Date:   Fri Nov 10 05:05:25 2023 +0000

    update readme

commit bbbbbbbbbbbbbbbbb (origin/main, origin/HEAD, main)
Author: user <mail@mail.com>
Date:   Thu Nov 9 23:51:16 2023 +0000

    Update README.md

リモートリポの更新をローカルリポに反映させる

git pull {remote_ref} {branchname}

(例)
git pull origin main

ローカルリポの内容をリモートリポに反映させる

git push {remote_ref} {branchname}

(例)
git push origin update-readme

ローカルリポの特定ブランチを削除する

通常
git branch -d {branch-name}

mainにマージされてないbranchを強制削除する場合
git branch -D {branch-name}
0
0
0

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
0
0