Kaigai Blog living abroad in my twenties

【My Study Note】How Git Works?

Infotech Web Developer

How Git Works?


As you now know, GitHub is a cloud-based hosting service, that lets you manage Git repositories from a user interface. It’s like a social network. You can follow users or accept code contributions from anywhere in the world.

This article is about how to pull the repository to your local device.

Btw, in Linux, any folder starting with a dot is a hidden folder.

A folder called .git is a hidden folder used to track all the changes. The .git folder is initialized by running the git INT command. As the repository is created on GitHub, it is not required for us to run it. GitHub handles all of this as part of its create new repo flow.

Git Workflow

Git uses workflows that can be broken into three states

  • Modified
  • Staged
  • Committed

Modified

Let’s start with the first state, adding removing and updating any file inside the repository is considered a modified state. Git knows the file has changed but does not track it.

Staged

This is where the staging state comes in. In order for Git to track a file, it needs to be put in the staged area. Once added, any modifications are tracked. Which offers a security blanket prior to committing the changes.

Committed

The last state is the committed state. Committing a file in Git is like a save point in many ways. Git will save the file and have a snapshot of the current changes.

Example


Suppose you have a workflow that contains the three stages just mentioned, as well as the remote repository, a file is added from the working directory to the staging area. From there the file is committed, and then pushed to the remote repository.

From the remote repository, the file can now be fetched and checked out or merged to a working directory.