Week 7 · Lesson 2 of 10

The Git Workflow and Repository Setup

0% Complete

Core Idea

Git organizes work into a sequence of locations: the working directory, the staging area, the local repository, and, when collaboration or remote access is needed, the remote repository.

Understanding these locations is the foundation for understanding Git commands. Each command moves information between specific parts of the workflow.

How It Works

The working directory is the project folder in which you create, edit, rename, and delete files. These are active file-system changes. They are not yet permanent entries in Git history.

The staging area is the intermediate selection area between the working directory and the local repository. Staging means identifying which current changes should be included in the next commit.

The local repository stores committed versions and project history on your computer. A commit moves the currently staged snapshot into this repository.

The remote repository is an online Git repository, commonly hosted on GitHub. Pushing sends local commits to the remote. Fetching or pulling brings remote information back toward the local repository and working directory.

The basic direction of work is:

Working directory -> staging area -> local repository -> remote repository

The corresponding actions are:

Edit -> add -> commit -> push

This layered workflow prevents every file edit from becoming a permanent saved version automatically. You can make several changes, inspect them, choose the ones that belong together, and only then commit them.

Repository Creation by Initialization

To begin tracking an existing local project folder, open a terminal in that folder and run:

git init

This initializes an empty Git repository inside the current directory. Git creates a hidden directory named .git. That hidden directory contains Git's internal repository data, including information used to track changes, commits, and history.

The project folder remains the working directory. The .git directory is what makes that folder a Git repository.

You can verify that the hidden directory exists with a command that displays hidden files, such as:

ls -la

The .git directory is managed by Git. It is the internal core of the repository rather than an ordinary project folder for manual editing.

Repository Creation by Cloning

A second way to begin is to copy an existing remote repository to your computer:

git clone <repository-url>

Cloning downloads the remote repository into a new local folder. The downloaded folder includes both the project files and its .git directory, so it is immediately a complete local Git repository.

Initialization and cloning therefore begin from opposite directions:

  • git init starts with a local folder and turns it into a repository.
  • git clone starts with a remote repository and creates a local copy.

Checking Installation and Repository State

Before working with Git, verify that it is installed:

git --version

A version result indicates that Git is available. An error indicates that installation or command access still needs attention.

Once inside a repository, inspect its current state with:

git status

Git status reports which branch you are on and identifies files that are modified, newly created, untracked, staged, or otherwise pending action.

Tracked files are files Git already knows from earlier commits or staging. Untracked files are new files that Git has not yet been told to include.

Why It Matters

Many Git mistakes are location mistakes. A learner may believe a change is safely saved when it exists only in the working directory, or may believe it is on GitHub when it has only been committed locally.

The four-location model removes that ambiguity. Before running a command, ask two questions:

  1. Where is the change now?
  2. Where should it move next?

For Example

  • A modified file in the working directory must be staged before it enters the next commit.
  • A staged change must be committed before it becomes part of local history.
  • A local commit must be pushed before it appears in the remote repository.

Practical Application

A clean setup sequence is:

  1. Open a terminal.
  2. Verify Git with git --version.
  3. Navigate to the intended project directory.
  4. Either run git init or clone an existing repository with git clone <repository-url>.
  5. Confirm the repository state with git status.
  6. When using git init, verify that the .git directory exists if you need to confirm initialization.

After cloning, inspect the downloaded files and run git status. The repository should already know its committed files and branch state because its history was included in the clone.

Trade-Offs and Limitations

Running git init creates local repository history, but it does not automatically connect the repository to GitHub.

Cloning creates a local copy of a remote repository, but subsequent remote changes do not appear automatically. They must later be fetched or pulled.

General terminal commands such as cd, pwd, touch, mkdir, and ls are not Git commands. They manage directories and files around the repository, while Git commands manage version-control state.

Key Takeaway

Git work moves through distinct locations. Initialize a local folder with git init or copy a remote repository with git clone, then use git status to understand exactly where the repository stands before taking the next action.

Back to top