Git Workspace Basics
What is a Git Workspace?
A Git workspace is the local directory where you work on your project files. It represents the actual files and directories on your computer, allowing you to modify, create, and delete files before committing changes to the Git repository.
Key Components of Git Workspace
1. Working Directory
The working directory is the root folder of your project where you directly edit files. It contains the current state of your project files.
graph LR
A[Working Directory] --> B[Staging Area]
B --> C[Local Repository]
C --> D[Remote Repository]
2. Staging Area
The staging area is an intermediate space where you prepare files for commit. It allows you to selectively choose which changes to include in your next commit.
3. Local Repository
The local repository stores the complete history of your project, including all commits, branches, and version changes.
Basic Git Workspace Commands
Command |
Description |
Example |
git init |
Initialize a new Git repository |
git init my-project |
git add |
Add files to staging area |
git add README.md |
git status |
Check workspace status |
git status |
git commit |
Save changes to local repository |
git commit -m "Initial commit" |
Setting Up Your Git Workspace
Installation
On Ubuntu 22.04, install Git using:
sudo apt update
sudo apt install git
Configuration
Set up your Git identity:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Workspace Best Practices
- Always work in a dedicated project directory
- Use meaningful commit messages
- Regularly pull and push changes
- Create
.gitignore
to exclude unnecessary files
LabEx Workspace Recommendation
For developers learning Git, LabEx provides interactive environments that simulate real-world Git workspaces, helping you practice and understand Git concepts effectively.