Structure and Mechanism of Git

Joint Development

Git is a distributed version control system that can record and manage change history of source code and documents.
This knowledge describes its structure and mechanism.

Sponsored Links

Structure and mechanics of Git

We describe the directories and repositories used within Git as the structure and mechanism of Git.
The outline of each directory and repository, their relationships, and the commands to be linked is as follows.

Git Structure

We describe each directory and repository in detail based on the above structure diagram.

  • Local Environment
    • Since Git is a distributed version control system, you can copy the source to your local environment for simultaneous development.
    • The local environment uses a PC or a local server.
  • Shared Env.
    • It is a shared environment with a remote repository.
    • You may create a public server for the shared environment yourself. However, it is easy to manage by using cloud services such as GitHub, GitLab, and Cloud Source Repositories of GCP.
  • Repository
    • It is a place to record the status of files and directories. The state is retained as an update history. It is possible to manage under any directory.
    • The entity is the “.git” directory directly under the work tree. You can create a new repository just by copying the “.git” directory to another directory.
  • Local Repository
    • It’s a locally placed repository.
    • It is often installed on a PC or local server.
  • Remote Repository
    • It is a repository that can be accessed externally and shared by multiple people.
    • You can also develop and set up a remote repository yourself. However, it is easy to manage by using cloud services such as GitHub, GitLab, and Cloud Source Repositories of GCP.
  • Worktree
    • It is a working directory.
    • It is a directory that manages the status and update history in Git. The updated contents under this directory will be managed.
    • If you create a worktree with “git clone” without specifying a name, the worktree name is the same as the remote repository name.
  • Index
    • It is an area where you can check and manage the updated information executed in the work tree before committing it to the local repository.
  • Branch
    • It branches the entire managed source so that it can be managed as a separate version. Because it is independent between different branches, updating a file on one branch does not affect the different branches.
    • The “master” branch is created by default. As a use case, you create a “develop” branch from the “master” branch. Then you can develop in the “develop” branch, merge it into the “master” branch at release, and commit.
    • “HEAD” represents the beginning of the branch in use. By default, it represents the beginning of “master”. You can change the branch by moving “HEAD”.
    • You can switch branch with “git checkout”.
  • Local Branch
    • It’s a branch in your local repository. The “master” branch is created by default.
  • Remote-tracking Branch
    • It’s a local branch that copies the state of a remote branch in a local repository.
    • The branch name is represented by “repository name / remote branch name”. For example, “origin / master” is a branch in a local repository that is a copy of the “master” branch of the default repository represented by “origin”.
  • Remote Branch
    • It’s a branch in a remote repository.

Sponsored Links