230 lines
5.4 KiB
Markdown
230 lines
5.4 KiB
Markdown
# Git Commands Reference
|
|
|
|
This document provides essential Git commands for developing the Enterprise Asset Management System.
|
|
|
|
## Basic Development Workflow
|
|
|
|
### 1. **Check Status & See Changes**
|
|
```bash
|
|
git status # See what files are modified
|
|
git diff # See specific changes in files
|
|
git diff --staged # See staged changes
|
|
```
|
|
|
|
### 2. **Stage & Commit Changes**
|
|
```bash
|
|
# Stage specific files
|
|
git add filename.js
|
|
git add frontend/src/views/
|
|
|
|
# Stage all changes
|
|
git add .
|
|
|
|
# Commit with message
|
|
git commit -m "Add user authentication feature"
|
|
```
|
|
|
|
### 3. **Push to Remote**
|
|
```bash
|
|
git push # Push current branch to remote
|
|
git push origin main # Push main branch explicitly
|
|
```
|
|
|
|
## Feature Development Workflow
|
|
|
|
### **Option A: Simple (Direct to main)**
|
|
```bash
|
|
# Make changes, then:
|
|
git add .
|
|
git commit -m "Implement asset filtering feature"
|
|
git push
|
|
```
|
|
|
|
### **Option B: Feature Branches (Recommended)**
|
|
```bash
|
|
# Create and switch to feature branch
|
|
git checkout -b feature/asset-export
|
|
|
|
# Make changes, then:
|
|
git add .
|
|
git commit -m "Add CSV export functionality"
|
|
git push -u origin feature/asset-export
|
|
|
|
# When ready to merge:
|
|
git checkout main
|
|
git merge feature/asset-export
|
|
git push
|
|
git branch -d feature/asset-export # Delete local branch
|
|
```
|
|
|
|
## Quick Reference Commands
|
|
|
|
### **Daily Commands**
|
|
```bash
|
|
git pull # Get latest changes from remote
|
|
git add . # Stage all changes
|
|
git commit -m "Your message" # Commit with message
|
|
git push # Push to remote
|
|
```
|
|
|
|
### **Useful Checks**
|
|
```bash
|
|
git log --oneline -10 # See last 10 commits
|
|
git branch -a # See all branches
|
|
git remote -v # Check remote URLs
|
|
```
|
|
|
|
### **Undo Commands**
|
|
```bash
|
|
git reset HEAD~1 # Undo last commit (keep changes)
|
|
git checkout -- filename.js # Discard changes to file
|
|
git restore filename.js # Discard changes (newer syntax)
|
|
```
|
|
|
|
## Recommended Commit Message Format
|
|
|
|
```bash
|
|
git commit -m "Add asset search functionality
|
|
|
|
- Implement real-time search in Assets.vue
|
|
- Add debounced search input
|
|
- Update AssetRepository with search filters
|
|
- Add search tests"
|
|
```
|
|
|
|
## Advanced Commands
|
|
|
|
### **Branch Management**
|
|
```bash
|
|
git branch # List local branches
|
|
git branch -r # List remote branches
|
|
git branch -a # List all branches
|
|
git branch -d branch-name # Delete local branch
|
|
git push origin --delete branch-name # Delete remote branch
|
|
```
|
|
|
|
### **Stashing Changes**
|
|
```bash
|
|
git stash # Save changes temporarily
|
|
git stash pop # Restore stashed changes
|
|
git stash list # List all stashes
|
|
git stash drop # Delete latest stash
|
|
```
|
|
|
|
### **Remote Management**
|
|
```bash
|
|
git remote add origin <url> # Add remote repository
|
|
git remote -v # Show remote URLs
|
|
git remote set-url origin <new-url> # Change remote URL
|
|
```
|
|
|
|
### **Syncing with Remote**
|
|
```bash
|
|
git fetch # Download remote changes (don't merge)
|
|
git pull # Download and merge remote changes
|
|
git pull --rebase # Pull with rebase instead of merge
|
|
```
|
|
|
|
## Common Scenarios
|
|
|
|
### **Starting a New Feature**
|
|
```bash
|
|
git checkout main
|
|
git pull
|
|
git checkout -b feature/new-feature
|
|
# Make changes
|
|
git add .
|
|
git commit -m "Implement new feature"
|
|
git push -u origin feature/new-feature
|
|
```
|
|
|
|
### **Updating Your Branch with Latest Main**
|
|
```bash
|
|
git checkout main
|
|
git pull
|
|
git checkout feature/your-feature
|
|
git merge main
|
|
# Or use rebase for cleaner history:
|
|
git rebase main
|
|
```
|
|
|
|
### **Quick Fix Workflow**
|
|
```bash
|
|
git checkout main
|
|
git pull
|
|
git checkout -b hotfix/fix-critical-bug
|
|
# Make fix
|
|
git add .
|
|
git commit -m "Fix critical bug in authentication"
|
|
git push -u origin hotfix/fix-critical-bug
|
|
# Create pull request or merge directly
|
|
```
|
|
|
|
## Best Practices
|
|
|
|
1. **Always pull before starting work:**
|
|
```bash
|
|
git pull
|
|
```
|
|
|
|
2. **Use descriptive commit messages:**
|
|
```bash
|
|
git commit -m "Fix asset deletion not updating UI cache"
|
|
```
|
|
|
|
3. **Stage changes selectively:**
|
|
```bash
|
|
git add -p # Interactive staging
|
|
```
|
|
|
|
4. **Check what you're committing:**
|
|
```bash
|
|
git diff --staged
|
|
```
|
|
|
|
5. **Use feature branches for new features:**
|
|
```bash
|
|
git checkout -b feature/asset-export
|
|
```
|
|
|
|
## Emergency Commands
|
|
|
|
### **Undo Last Commit (but keep changes)**
|
|
```bash
|
|
git reset --soft HEAD~1
|
|
```
|
|
|
|
### **Completely Discard All Changes**
|
|
```bash
|
|
git reset --hard HEAD
|
|
```
|
|
|
|
### **Go Back to Previous Commit**
|
|
```bash
|
|
git log --oneline # Find commit hash
|
|
git reset --hard <commit-hash>
|
|
```
|
|
|
|
### **Create Branch from Specific Commit**
|
|
```bash
|
|
git checkout -b new-branch <commit-hash>
|
|
```
|
|
|
|
## Project-Specific Notes
|
|
|
|
- **Main branch:** `main`
|
|
- **Remote name:** `origin`
|
|
- **Typical feature branch naming:** `feature/description` or `fix/description`
|
|
- **For this project:** Always test locally before pushing to ensure the app builds and runs correctly
|
|
|
|
## Pro Tips
|
|
|
|
- Use `git add -p` to selectively stage parts of files
|
|
- Use `git log --graph --oneline --all` for visual commit history
|
|
- Set up aliases for common commands in `~/.gitconfig`
|
|
- Use `git blame filename` to see who changed each line
|
|
- Use `git show <commit-hash>` to see details of a specific commit
|
|
|
|
---
|
|
|
|
**Remember:** Always ensure your code works locally before committing and pushing to avoid breaking the remote repository! |