0
0

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 入門】新人が最初に覚えるべき基本コマンドと開発フローまとめ

0
Posted at

業務で Git を使う際に、最低限これだけはマスターしておくべき基本操作をまとめました。
新人研修・自分用の備忘録としても使える内容です。


0. Git を使い始める準備(初回のみ)

リポジトリの初期化

git init

GitHub などのリモートリポジトリと連携

git remote add origin <repository-url>
git branch -M main
git push -u origin main

1. 開発の基本サイクル(最重要)

毎日の開発で 何度も使う基本フロー です。

# 1. 変更の確認
git status

# 2. 変更をステージング(全部追加)
git add .

# 3. コミット(メッセージを添えて記録)
git commit -m "feat: 〇〇機能の実装"

# 4. リモートへ送信
git push origin <branch-name>

2. 最新状態の取得(チーム開発では必須)

他メンバーの変更を取り込み、常に最新状態で作業します。

# リモートの変更を取得して反映
git pull origin <branch-name>

# 事前に差分だけ確認したい場合
git fetch origin

3. ブランチ操作

補足:git checkout について
以前は checkout が主流でしたが、現在は switch / restore が推奨されています。

作業単位ごとにブランチを分けるのが基本です。

# ブランチ作成と切り替え(同時)
git switch -c <new-branch-name>

# 既存ブランチへ切り替え
git switch main

# ブランチを統合(main に作業内容を取り込む)
git switch main
git merge <branch-name>

4. よく使うコミットメッセージのプレフィックス

チームで接頭辞を統一すると、履歴が非常に読みやすくなります。

  • feat: 新機能追加
  • fix: バグ修正
  • docs: ドキュメント修正
  • refactor: リファクタリング(機能変更なし)
git commit -m "fix: バリデーションエラーを修正"

5. よくあるポイント(新人がつまずきやすい点)

  • git add .全変更が対象になるので注意
  • git pull 前に git status で作業中変更がないか確認
  • 1コミット = 1つの意味ある変更を意識する

まとめ

  • status → add → commit → push が基本サイクル
  • チーム開発では pull / fetch を習慣化
  • ブランチ運用とコミットメッセージは最初から意識する

この内容を押さえておけば、業務で Git を使う上でまず困ることはありません。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?