Command Line Workflow
Git Basic Workflow
graph TD
A[Working Directory] --> |add| B[Staging Area]
B --> |commit| C[Local Repository]
C --> |push| D[Remote Repository]
Essential Git Commands
Command |
Purpose |
Example |
git init |
Initialize repository |
git init myproject |
git clone |
Copy remote repository |
git clone https://github.com/user/repo.git |
git add |
Stage changes |
git add file.txt |
git commit |
Save changes |
git commit -m "Initial commit" |
git status |
Check repository status |
git status |
git push |
Upload local changes |
git push origin main |
git pull |
Download remote changes |
git pull origin main |
Repository Initialization
Create New Repository
## Create project directory
mkdir myproject
cd myproject
## Initialize git repository
git init
Staging and Committing
Adding Files
## Stage specific file
git add README.md
## Stage all changes
git add .
Committing Changes
## Commit with message
git commit -m "Add project documentation"
## Commit with detailed description
git commit -m "Feature: Add user authentication
- Implemented login mechanism
- Created user registration flow"
Branching Strategies
gitGraph
commit
branch develop
checkout develop
commit
branch feature
checkout feature
commit
checkout develop
merge feature
checkout main
merge develop
Remote Repository Interactions
Connecting to Remote
## Add remote repository
git remote add origin https://github.com/user/repo.git
## Verify remote connections
git remote -v
Pushing Changes
## Push to main branch
git push origin main
## Push to specific branch
git push origin feature-branch
Collaborative Workflow
Pulling Latest Changes
## Update current branch
git pull origin main
## Fetch without merging
git fetch origin
LabEx Recommendation
Practice these workflows in LabEx's interactive Git environments to build practical skills and confidence.
Best Practices
- Commit frequently
- Write clear, descriptive commit messages
- Use branches for feature development
- Always pull before pushing