πŸš€ AI Magicx API v1.0 is Live!
View API Docs
Magicx

File Operations Guide | Github Tools

Last updated: July 1, 2025
By AI Magicx Team

#File Operations Guide

Learn how to read, write, and manage files in your GitHub repositories using natural language commands.

#πŸ“– Reading Files

#Basic File Reading

Ask the AI to show you any file in your repository:

"Show me the README.md file" "What's in the package.json?" "Display the contents of src/index.js" "Read the config/database.yml file"

#Reading Multiple Files

"Show me all files in the components folder" "What's in both the .env.example and .env.local files?" "Display all configuration files"

#Partial File Reading

"Show me the first 50 lines of src/app.js" "What's at the top of the main.py file?" "Show me the imports section of components/Header.tsx"

#File Information

"When was the README last modified?" "Who was the last person to edit src/utils.js?" "What's the file size of assets/logo.png?"

#πŸ“ Creating and Updating Files

#Creating New Files

"Create a new component called UserProfile.tsx in the components folder" "Add a new file called .gitignore with standard Node.js ignores" "Create a new API route in pages/api/users.js"

#Updating Existing Files

"Add a new function called validateEmail to src/utils.js" "Update the README to include installation instructions" "Add error handling to the login function in auth.js"

#File Templates

"Create a new React component called ProductCard with props for title, price, and image" "Generate a new Express route handler for user authentication" "Create a new TypeScript interface for User data"

#Batch Operations

"Update all component files to use the new import statement" "Add proper TypeScript types to all files in the utils folder" "Create test files for all components in the components directory"

#πŸ—‚οΈ Directory Operations

#Listing Directory Contents

"What's in the src folder?" "Show me all files in the components directory" "List everything in the root directory" "What subdirectories are in the lib folder?"

#Directory Structure

"Show me the complete folder structure" "What's the organization of the src directory?" "Display the project hierarchy"

#Finding Files

"Find all TypeScript files" "Where are the configuration files?" "Show me all test files" "Find files containing 'database' in the name"

#πŸ—‘οΈ Deleting Files

#Single File Deletion

"Delete the old-component.js file" "Remove the unused config.old file" "Delete the temporary test file"

#Safety Confirmation

The AI will always confirm before deleting:

  • Shows you what will be deleted
  • Asks for explicit confirmation
  • Warns about potential impacts

#Bulk Deletion

"Remove all .log files" "Delete all files in the temp directory" "Clean up the old backup files"

⚠️ Warning: Be careful with bulk deletions. The AI will show you what will be deleted and ask for confirmation.

#πŸ” Advanced File Operations

#File Comparison

"Compare the old and new versions of app.js" "What changed in the last commit to README.md?" "Show me the differences between development and production configs"

#File Search Within Content

"Find all files that import React" "Show me files containing the word 'authentication'" "Which files use the old API endpoint?"

#File Dependencies

"What files import the Button component?" "Show me all dependencies of the user module" "Which files would be affected if I change this interface?"

#πŸ’‘ Smart File Operations

#Context-Aware Creation

The AI understands your project structure and will:

  • Use appropriate file extensions
  • Follow your project's naming conventions
  • Add proper imports and dependencies
  • Include necessary boilerplate code

#Intelligent Updates

When updating files, the AI will:

  • Preserve existing formatting and style
  • Maintain proper syntax
  • Add necessary imports
  • Follow your code patterns

#Error Prevention

The AI helps prevent mistakes by:

  • Warning about overwrites
  • Checking for naming conflicts
  • Validating file paths
  • Ensuring proper permissions

#πŸ“‹ Common File Operation Examples

#React Development

"Create a new React component for displaying user profiles" "Add state management to the existing Cart component" "Update the App.js to include the new routing"

#Node.js Backend

"Create a new Express middleware for authentication" "Add a new database model for products" "Update the API routes to handle the new user endpoints"

#Configuration Management

"Update the webpack config to include the new plugin" "Add environment variables for the new API keys" "Create a new configuration file for testing"

#Documentation

"Update the API documentation in docs/api.md" "Create a contributing guide for new developers" "Add changelog entries for the new release"

#🎯 Best Practices

#1. Be Specific with Paths

Instead of: "Update the component" Try: "Update the UserProfile component in src/components/UserProfile.tsx"

#2. Provide Context

"Add error handling to the login function (it's currently missing try-catch blocks)" "Create a new component for the dashboard page (should include charts and user stats)"

#3. Specify Requirements

"Create a TypeScript interface with proper types" "Add JSDoc comments to the new function" "Include unit tests for the new utility function"

#4. Review Before Committing

"Show me what changed before I commit" "Review the new component for any issues" "Validate the configuration changes"

#🚨 Safety Features

#Backup Confirmation

  • Files are backed up before major changes
  • You can revert changes if needed
  • History is preserved in Git

#Permission Checks

  • Verifies write permissions before operations
  • Respects repository access levels
  • Warns about protected branches

#Validation

  • Syntax checking for code files
  • Format validation for config files
  • Dependency verification for imports

#πŸ”§ Troubleshooting

#"File not found"

  • Check the file path is correct
  • Verify you have access to the repository
  • Ensure the file exists in the current branch

#"Permission denied"

  • Check repository write permissions
  • Verify GitHub app authorization
  • Contact repository owner if needed

#"File too large"

  • GitHub has file size limits (100MB)
  • Consider using Git LFS for large files
  • Split large files into smaller parts

#✨ Pro Tips

  1. Use relative paths when possible: src/components/Button.tsx
  2. Mention file types for better context: "TypeScript component", "JSON config"
  3. Ask for explanations after operations: "Explain what this new function does"
  4. Request reviews before major changes: "Review this before I save it"