git
The git
module provides comprehensive Git version control operations for CodeboltJS. It enables complete Git workflow automation including repository initialization, branch management, commit operations, and remote synchronization.
- init - Initializes a new Git repository. Can be used in the current directory or at a specified path.
- status - Retrieves the status of the Git repository. Shows working tree status including staged, unstaged, and untracked files.
- add - Adds changes in the local repository to the staging area. Can add specific files or all changes using addAll().
- commit - Commits the staged changes in the local repository with the given commit message.
- branch - Creates a new branch in the Git repository. Essential for feature development and parallel work streams.
- checkout - Checks out a branch or commit in the Git repository. Switches the working directory to the specified branch.
- logs - Retrieves the commit logs for the Git repository. Shows commit history with details like hash, message, author, and date.
- diff - Retrieves the diff of changes for a specific commit in the local repository.
- clone - Clones a Git repository from the given URL to the specified path.
- pull - Pulls the latest changes from the remote repository to the local repository.
- push - Pushes local repository changes to the remote repository.
Key Features
Repository Management
- Repository Initialization: Create new Git repositories with
init()
- Status Monitoring: Track working tree status with
status()
- History Access: View commit history and logs with
logs()
File Operations
- Staging Changes: Add files to staging area with
add()
andaddAll()
- Committing: Save changes with descriptive commit messages using
commit()
- Diff Analysis: Compare changes between commits with
diff()
Branch Management
- Branch Creation: Create new branches for feature development with
branch()
- Branch Switching: Navigate between branches using
checkout()
- Parallel Development: Work on multiple features simultaneously
Remote Operations
- Repository Cloning: Clone remote repositories with
clone()
- Synchronization: Keep repositories in sync with
pull()
andpush()
- Collaboration: Enable team collaboration through remote operations
Common Workflows
Complete Git Initialization Workflow
// Initialize repository and make first commit
await codebolt.git.init();
await codebolt.fs.createFile('README.md', '# My Project\n\nProject description.');
await codebolt.git.addAll();
await codebolt.git.commit('Initial commit');
Feature Development Workflow
// Create feature branch and develop
await codebolt.git.branch('feature/user-auth');
await codebolt.git.checkout('feature/user-auth');
await codebolt.fs.createFile('auth.js', '// Authentication logic');
await codebolt.git.addAll();
await codebolt.git.commit('Implement user authentication');
await codebolt.git.checkout('main');
Status Monitoring Workflow
// Check status throughout development
const status = await codebolt.git.status();
if (status.untracked?.length > 0) {
await codebolt.git.addAll();
await codebolt.git.commit('Add new files');
}
Commit History Analysis
// Analyze project history
const logs = await codebolt.git.logs();
const latestCommit = logs.logs[0];
console.log(`Latest: ${latestCommit.message} by ${latestCommit.author}`);
Method Categories
Core Operations
init()
- Initialize new repositorystatus()
- Check repository statusadd()
/addAll()
- Stage changescommit(message)
- Save changes
Branch Operations
branch(name)
- Create new branchcheckout(branch)
- Switch brancheslogs()
- View commit history
Advanced Operations
diff(commitHash)
- Compare changesclone(url, path)
- Clone repositorypull()
- Fetch remote changespush()
- Send local changes
Integration with File System
The git module works seamlessly with the fs
module for complete development workflows:
// Create project structure
await codebolt.fs.createFolder('src', '.');
await codebolt.fs.createFile('index.js', 'console.log("Hello World");', './src');
// Version control the project
await codebolt.git.init();
await codebolt.git.addAll();
await codebolt.git.commit('Initial project structure');
// Continue development
await codebolt.fs.updateFile('index.js', './src', 'console.log("Updated!");');
await codebolt.git.addAll();
await codebolt.git.commit('Update main file');
Error Handling
All git methods return promises and should be used with proper error handling:
try {
const result = await codebolt.git.commit('My commit message');
if (result.success) {
console.log('✅ Operation successful');
} else {
console.log('❌ Operation failed:', result.message);
}
} catch (error) {
console.error('Error:', error.message);
}
Best Practices
Commit Messages
- Use clear, descriptive commit messages
- Follow conventional commit format (feat:, fix:, docs:)
- Keep commits atomic and focused
Branch Management
- Use descriptive branch names (feature/login, hotfix/bug-123)
- Create branches for each feature or bug fix
- Switch back to main after completing work
Workflow Automation
- Check status before making commits
- Use addAll() for convenience in development
- Leverage logs for debugging and project analysis
The git module enables complete version control automation, making it easy to implement sophisticated development workflows and CI/CD processes.