Fundamentals 8 min read

Master Git: Understand Workspaces, Staging, and Commit Workflows

This guide explains Git's four core areas—working directory, index, repository, and remote—describes file states and the typical workflow, and provides essential commands for initializing repositories, tracking changes, committing, and synchronizing with remote servers.

Open Source Linux
Open Source Linux
Open Source Linux
Master Git: Understand Workspaces, Staging, and Commit Workflows

1.1 Four Work Areas

Git has four work areas: Working Directory, Index (Stage), Repository (Git Directory), and Remote Directory. Files move among these areas during version control.

Workspace

The place where you keep project files.

Index / Stage

A temporary area that stores changes before they are committed; it is essentially a file that records the list of changes to be committed.

Repository

The safe storage for all committed versions; HEAD points to the latest commit.

Remote

A remote server that hosts the repository, acting like a shared computer for team collaboration.

1.2 Typical Workflow

1. Modify or add files in the Working Directory. 2. Add files to the Index (stage them). 3. Commit staged files to the Repository. Thus files can be in three states: Modified, Staged, Committed.

1.3 File States

Git tracks files as Untracked, Modified, Staged, or Unmodified. Untracked files are not yet added to the repository; they become Staged after git add. Modified files are changed in the Working Directory; they become Staged after git add. Staged files become Unmodified after git commit. Use git reset HEAD <file> to unstage.

2.1 Create a Repository

git init

– initialize a new repository in the current directory. git init <project-name> – create and initialize a new directory. git clone <url> – clone an existing remote repository.

2.2 View File Status

git status <filename>

– status of a specific file. git status – status of all files.

2.3 Working Directory ↔ Index

git add <file1> [<file2> ...]

– add specific files to the Index. git add <dir> – add a directory (including sub‑directories). git add . – add all changes in the current directory.

2.4 Index ↔ Repository

git commit -m "message"

– commit staged changes to the Repository.

2.5 Remote Operations

git pull

– fetch and merge changes from the remote. git push <remote> <branch> – push local commits to the remote repository.

2.6 Other Useful Commands

git config --list

– display current Git configuration. git config -e [--global] – edit configuration file. git config --global user.email "[email protected]" – set global email. git config --global user.name "Your Name" – set global username.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

workflowGitVersion ControlRepositorycommandsStaging
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.