0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Git 使い方まとめ

Posted at

Gitの使用は基本ですが、度々忘れることがあるので備忘用に記載します。

初期設定系

git config --global user.name "Your Name"
git config --global user.email "your@email.com"
git config --global init.defaultBranch main

ローカルの基本操作

git init                      # 既存フォルダをGit管理下に置く
git clone <URL>              # リモートリポジトリをローカルにコピー

変更状況の確認

git status                   # 変更されたファイル一覧
git diff                     # 実際の変更内容(差分)

ステージング

git add <ファイル名>         # ステージに追加
git add .                    # 全部追加

コミット

git commit -m "説明文"        # スナップショットを記録

リモートの追加&確認

git remote add origin <URL>  # リモート設定(初回のみ)
git remote -v                # 現在のリモート確認

プッシュ・プル
git push origin main # ローカル → リモートに反映
git pull origin main # リモート → ローカルに反映

ブランチ作成・切り替え

git branch <ブランチ名> # 作成
git switch <ブランチ名> # 切り替え

ブランチ削除

git branch -d <ブランチ名> # マージ済みブランチを削除

マージ

git merge <ブランチ名> # 今いるブランチに指定ブランチを統合

競合発生時

git add <修正済ファイル>
git commit # 解決後にコミット

コミット前の変更を取り消し

git restore <ファイル名> # 編集をなかったことに

add した変更を取り消し
git reset HEAD <ファイル名>

直前のコミットをやり直し

git commit --amend

よく使う便利コマンド

git log --oneline --graph --all   # 見やすいログ
git stash                         # 途中作業を一時退避
git stash pop                     # 一時退避の復元

よくあるワークフロー
①main ブランチを pull
②作業ブランチを切る git checkout -b feature/hogehoge
③作業して commit
③git push origin feature/hogehoge
④PR(プルリク)を出す
⑤レビュー&マージ
⑥main を最新化して次のタスクへ

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?