# Git Basics: A Beginner's Guide
## What is Git?
Git is a distributed version control system that helps developers track changes in
their code, collaborate with others, and manage different versions of their
projects.
## Essential Git Commands
### Setting Up
```bash
# Configure your identity
git config --global [Link] "Your Name"
git config --global [Link] "[Link]@[Link]"
# Initialize a new repository
git init
```
### Basic Workflow
```bash
# Check status of your repository
git status
# Add files to staging area
git add [Link] # Add specific file
git add . # Add all changes
# Commit changes
git commit -m "Descriptive message about changes"
# View commit history
git log
git log --oneline # Condensed view
```
### Working with Remote Repositories
```bash
# Clone a repository
git clone [Link]
# Add a remote repository
git remote add origin [Link]
# Push changes to remote
git push origin main
# Pull latest changes
git pull origin main
```
### Branching
```bash
# Create a new branch
git branch feature-branch
# Switch to a branch
git checkout feature-branch
# Create and switch in one command
git checkout -b feature-branch
# Merge branch into current branch
git merge feature-branch
# Delete a branch
git branch -d feature-branch
```
## Best Practices
1. Commit often with clear, descriptive messages
2. Pull before you push to avoid conflicts
3. Use branches for new features or experiments
4. Review changes before committing
5. Don't commit sensitive information (passwords, API keys)
## Common Mistakes to Avoid
- Committing directly to main/master branch in team projects
- Forgetting to pull before starting work
- Writing vague commit messages like "fixed stuff"
- Committing large binary files
## Need Help?
```bash
git help # General help
git help <command> # Help for specific command
```
Happy coding!