1
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の基本的なワークフロー

Posted at

はじめに

Gitはソースコードのバージョン管理のため、使われていっており、Gitを楽に使用するためのツールや拡張機能もたくさんあります。
しかし、Gitのワークフローをきちんと理解していないまま、Gitやツールを使っていることではないかと思いました。
そのため、Gitの基本的なワークフローについて、簡単に整理してみたいと思います。

Gitの各領域

Gitは3つの領域で区分できます。
(ローカルリポジトリリモートリポジトリを別領域にすると4つで区分)

  1. 作業ディレクトリ (Working Directory、Working Tree)
    実際にファイルを修正する作業領域

  2. ステージング領域 (Staging Area、Index)
    コミットする前に変更内容を管理・一時的に保持する領域

  3. リポジトリ (Repository)
    ファイルの変更履歴が格納される領域
    ローカルリポジトリ(Local Repository)リモートリポジトリ(Remote Repository)がある

ただ、今回は以下のように5つに領域を細分化してワークフローを整理して見ます。

  1. 作業ディレクトリ (Working Directory)
  2. ステージング領域 (Staging Area)
  3. ローカルブランチ (Local Branch) : Local Repositoryに含まれるブランチ
  4. リモート追跡ブランチ (Remote-Tracking Branch) : Local Repositoryに含まれるブランチ
  5. リモートブランチ (Remote Branch) : Remote Repositoryに含まれるブランチ

Gitの基本的なワークフロー

image.png

  • git add
    作業ディレクトリの変更内容をステージング領域に追加
  • git commit
    ステージング領域の変更内容をローカルブランチに追加
  • git push
    ローカルブランチの内容をリモート追跡ブランチリモートブランチに反映
  • git fetch
    リモートブランチの内容をリモート追跡ブランチに反映
  • git merge
    リモート追跡ブランチの内容をローカルブランチに統合 (作業ディレクトリにも反映される)
  • git pull
    git fetchgit mergeをまとめて行う

おわりに

実際に作業するときには、もっと複雑なワークフローで、より多くのGitの機能を使用しますが、今回は簡単に基本的なワークフローだけを整理して見ました。

1
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
1
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?