Version Control Basics
What is Git?
- Distributed version control system
- Tracks changes in your code over time
- Enables collaboration with other developers
- Maintains history of your project
Essential Git Commands
# Initialize a new Git repository
git init
# Add files to staging area
git add filename # Add specific file
git add . # Add all files
# Commit changes
git commit -m "Your commit message"
# Check repository status
git status
# View commit history
git log
# Create and switch to a new branch
git checkout -b branch-name
# Switch between branches
git checkout branch-name
GitHub Basics
- Platform for hosting Git repositories
- Enables collaboration with others
- Provides tools for code review
- Offers project management features
Common GitHub Workflow
# Clone a repository
git clone repository-url
# Push changes to GitHub
git push origin branch-name
# Pull updates from GitHub
git pull origin branch-name
# Create a pull request
# Done through GitHub's web interface
Best Practices
- Write clear, descriptive commit messages
- Commit frequently and in logical chunks
- Use branches for new features/fixes
- Keep your repository up to date
- Review changes before committing