Lesson 14: GitHub Best Practices

What You'll Learn

In this final lesson, you'll learn professional Git and GitHub workflows, best practices, and tips to level up your skills. These practices will help you work effectively in teams and contribute to real-world projects.

Congratulations!

You've learned the fundamentals of Git and GitHub! You can now:

  • ✅ Create repositories
  • ✅ Make commits
  • ✅ Work with branches
  • ✅ Push and pull changes
  • ✅ Resolve conflicts
  • ✅ Create pull requests
  • ✅ Collaborate with others

Part 1: Commit Best Practices

Write Good Commit Messages

Good Bad
Fix login button alignment on mobile fix
Add user authentication with JWT added stuff
Refactor database connection logic changes
Update dependencies to fix security issue update

The 7 Rules of Great Commits

  1. Separate subject from body with blank line
  2. Limit subject line to 50 characters
  3. Capitalize subject line
  4. Don't end subject with period
  5. Use imperative mood ("Add feature" not "Added feature")
  6. Wrap body at 72 characters
  7. Use body to explain what and why, not how

Part 2: Branching Strategies

Git Flow

A popular branching model for larger projects:

  • main - Production code
  • develop - Integration branch
  • feature/* - New features
  • release/* - Release preparation
  • hotfix/* - Emergency fixes

GitHub Flow (Simpler)

Recommended for most teams:

  1. main branch always deployable
  2. Create feature branches from main
  3. Open Pull Request early
  4. Merge after review
  5. Deploy immediately

Trunk-Based Development

For very fast-moving teams:

  • Short-lived feature branches (hours/days)
  • Frequent merges to main
  • Feature flags for incomplete work

Part 3: Repository Organization

Essential Files

File Purpose
README.md Project overview and setup instructions
.gitignore Files Git should ignore
LICENSE How others can use your code
CONTRIBUTING.md How to contribute to the project
CODE_OF_CONDUCT.md Community guidelines

Good README.md Structure

# Project Name

Brief description of what this project does.

## Installation

```bash
npm install
```

## Usage

```bash
npm start
```

## Features

- Feature 1
- Feature 2

## Contributing

See CONTRIBUTING.md

## License

MIT

Part 4: Security Best Practices

Never Commit

  • Passwords or API keys
  • Environment files (.env)
  • Database credentials
  • Private keys (.pem, .key)
  • Personal data

If You Accidentally Commit Secrets

  1. Rotate the credentials immediately
  2. Remove from history (requires force push)
  3. Consider repository as compromised

Use Environment Variables

# .env file (add to .gitignore!)
API_KEY=your_secret_key
DATABASE_URL=your_db_url

# .env.example file (commit this)
API_KEY=your_api_key_here
DATABASE_URL=your_database_url_here

Part 5: GitHub Features

Issues

Track bugs, features, and tasks:

  • Use labels (bug, enhancement, help wanted)
  • Assign to team members
  • Link to Pull Requests
  • Use milestones for releases

Projects

Kanban boards for project management:

  • To Do, In Progress, Done columns
  • Link issues and PRs
  • Track progress visually

Actions

Automate workflows (CI/CD):

  • Run tests on every push
  • Deploy automatically
  • Check code quality

Pages

Host static websites from repositories

Releases

Tag versions and distribute software

Part 6: Workflow Tips

Daily Workflow

# Morning routine
git switch main
git pull

# Start new feature
git switch -c feature/new-feature

# Work...
git add .
git commit -m "Add feature"

# End of day
git push -u origin feature/new-feature

# Create Pull Request on GitHub

Before Merging

# Update your feature branch with latest main
git switch main
git pull
git switch feature/new-feature
git merge main

# Resolve any conflicts
# Test everything
# Then create/update Pull Request

Part 7: Common Mistakes to Avoid

Mistake Why It's Bad Do Instead
Committing directly to main No review, can break prod Use feature branches
Large, messy commits Hard to review and debug Small, focused commits
Rewriting pushed history Breaks others' work Use revert instead of reset
Not pulling before push Causes conflicts Pull → Work → Push
Ignoring .gitignore Commits unwanted files Set up .gitignore first

Part 8: Useful Git Aliases

Save time with these shortcuts:

# Add to ~/.gitconfig

[alias]
    st = status
    co = checkout
    br = branch
    ci = commit
    unstage = reset HEAD --
    last = log -1 HEAD
    lg = log --oneline --graph --all
    undo = reset --soft HEAD~1

Now use them:

git st        # Instead of git status
git co main   # Instead of git checkout main
git lg        # Pretty log graph

Part 9: Continue Learning

Next Steps

  • Practice - Create projects and use Git daily
  • Contribute - Find beginner-friendly open source projects
  • Learn advanced topics:
    • Git rebase and interactive rebase
    • Cherry-picking commits
    • Git hooks
    • Submodules
    • Git bisect for debugging

Resources

Summary

Professional Practices

Practice Benefit
Clear commit messages Easier to understand history
Feature branches Isolated development
Pull Requests Code review and quality
Frequent commits Better tracking, easier debugging
Good README Helps others understand project
Proper .gitignore Clean repository

Final Thoughts

You now have all the skills needed to use Git and GitHub professionally! Remember:

  • 🎯 Practice makes perfect - use Git for all your projects
  • 🤝 Collaborate - work with others and contribute to open source
  • 📚 Keep learning - Git has many advanced features to explore
  • Ask for help - the Git community is friendly and helpful

Congratulations on completing this course! 🎉

You're now ready to manage code like a professional developer. Good luck on your coding journey!

Course Complete!

You've finished all 15 lessons of Git & GitHub Fundamentals. Feel free to:

  • Review any lessons you found challenging
  • Practice the exercises again
  • Start using Git in your own projects
  • Contribute to open source projects

Thank you for learning with us!