GitHub is where the world builds software. It's a platform that hosts Git repositories in the cloud and provides powerful collaboration features. In this lesson, you'll learn how to use GitHub to share your code, collaborate with others, and contribute to open-source projects.
By the end of this lesson, you will be able to:
After creating your account, set up your profile:
:bulb: :bulb: Pro Tip Your GitHub profile is often the first thing recruiters and potential collaborators see. Treat it as your professional coding portfolio. Consider creating a special repository named after your username to add a custom README to your profile.
Let's look at how major projects use GitHub:
A GitHub repository includes:
my-awesome-project
)Feature | Best Practice | Why It Matters |
---|---|---|
Naming | Use lowercase with hyphens | Consistency and URL-friendly |
Description | Include key technologies | Improves search visibility |
README | Add immediately | First impression matters |
.gitignore | Use templates | Prevents accidental commits |
License | Choose early | Defines usage rights |
Topics | Add relevant tags | Enhances discoverability |
If you have an existing local repository:
# Add remote repository
git remote add origin https://github.com/username/repository-name.git
# Verify remote
git remote -v
# See more details
git remote show origin
# Push to remote repository
git push -u origin main
# -u sets upstream, so next time you can just use:
git push
# List remotes
git remote
# List remotes with URLs
git remote -v
# Add a remote
git remote add <name> <url>
# Remove a remote
git remote remove <name>
# Rename a remote
git remote rename <old> <new>
# Change remote URL
git remote set-url origin <new-url>
# Fetch changes (download but don't merge)
git fetch origin
# Pull changes (fetch and merge)
git pull origin main
# Pull with rebase
git pull --rebase origin main
# Push to specific branch
git push origin branch-name
# Push all branches
git push --all
# Push tags
git push --tags
# Delete remote branch
git push origin --delete branch-name
# Set upstream branch
git branch --set-upstream-to=origin/main main
# Create and track remote branch
git checkout -b feature origin/feature
# See tracking information
git branch -vv
A professional README.md is crucial for project success. Include:
Example Professional README structure:
# Project Name



> Brief, compelling description of what this project does and why it matters.
## 🚀 Features
- ✨ Feature 1: Brief description
- 🔧 Feature 2: Brief description
- 📊 Feature 3: Brief description
## 📋 Prerequisites
- Node.js >= 14.0.0
- npm >= 6.0.0
## 🔧 Installation
```bash
# Clone the repository
git clone https://github.com/username/project-name.git
# Navigate to project directory
cd project-name
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
const project = require('project-name');
// Initialize with configuration
const instance = project.create({
apiKey: process.env.API_KEY,
environment: 'production'
});
// Use the API
const result = await instance.doSomething();
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
### Issues
Issues are the backbone of project management on GitHub:
- **Bug Reports**: Track and fix problems systematically
- **Feature Requests**: Collect and prioritize new ideas
- **Discussions**: Technical debates and decisions
- **Task Tracking**: Break down work into manageable pieces
Creating effective issues:
- **Title**: Be specific (❌ "Bug" vs ✅ "Login button unresponsive on mobile Safari")
- **Description**: Use issue templates for consistency
- **Reproduction Steps**: For bugs, provide minimal reproducible examples
- **Environment Details**: Include OS, browser, version info
- **Labels**: Use semantic labels (bug, enhancement, documentation, help wanted)
- **Milestones**: Group related issues for release planning
- **Assignees**: Clearly define ownership
> **💡 💡 Pro Tip**
> Many successful projects use issue templates. Check out how [Microsoft's TypeScript](https://github.com/microsoft/TypeScript/tree/main/.github/ISSUE_TEMPLATE) structures their templates for bugs, features, and questions.
### GitHub Pages
Host static websites directly from your repository:
1. Go to Settings → Pages
2. Select source branch
3. Choose folder (/ or /docs)
4. Your site will be available at: `https://username.github.io/repository-name`
### Gists
Share code snippets:
- Public or secret (not private)
- Support multiple files
- Can be embedded in websites
- Support comments
- Can be forked and starred
## SSH vs HTTPS
### HTTPS
- Easier to set up
- Works everywhere
- Requires password/token for each push
__CODE_BLOCK_9__`
### SSH
* More secure
* No password needed after setup
* Requires SSH key configuration
```bash
git clone git@github.com:username/repo.git
```
Setting up SSH:
```bash
# Generate SSH key
ssh-keygen -t ed25519 -C "your.email@example.com"
# Start SSH agent
eval "$(ssh-agent -s)"
# Add SSH key
ssh-add ~/.ssh/id_ed25519
# Copy public key
cat ~/.ssh/id_ed25519.pub
# Add this to GitHub: Settings → SSH and GPG keys
```
## Personal Access Tokens
Since password authentication is deprecated, use tokens:
1. Go to Settings -> Developer settings -> Personal access tokens
2. Click "Generate new token"
3. Select scopes (permissions)
4. Copy and save the token securely
5. Use token instead of password when pushing
## GitHub Best Practices
### One. **Repository Organization**
* Use clear, descriptive names following naming conventions
* Include comprehensive documentation (README, CONTRIBUTING, CODE\_OF\_CONDUCT)
* Configure .gitignore before first commit
* Choose license based on your goals (permissive vs copyleft)
* Add relevant topics for discoverability
* Set up branch protection rules early
* Enable issue templates and PR templates
### 2. **Commit Practices**
* Follow conventional commit format: `type(scope): description`
* Keep commits atomic (one logical change per commit)
* Write commit messages in imperative mood
* Sign commits with GPG for verification
* Never commit sensitive data (use .env files)
* Reference issues in commits: `fixes #123`
Example commit messages:
```
feat(auth): add OAuth2 integration with Google
fix(api): resolve memory leak in user service
docs(readme): update installation instructions
refactor(database): optimize query performance
```
### 3. **Branch Protection**
* Protect main/master branch against direct pushes
* Require pull request reviews (minimum 1-2 reviewers)
* Enable status checks (CI/CD must pass)
* Dismiss stale reviews when new commits are pushed
* Require branches to be up-to-date before merging
* Enable linear history for cleaner git log
### 4. **Security Best Practices**
* Enable Dependabot for automated security updates
* Use GitHub Secrets for sensitive data
* Enable security scanning (code scanning, secret scanning)
* Implement CODEOWNERS file for sensitive areas
* Regular security audits with `npm audit` or similar
* Use 2FA for all team members
* Rotate access tokens regularly
<details>
<summary>:emoji: Quick Reference: Security Checklist</summary>
| Task | Frequency | Tool/Method |
| ------------------ | -------------- | ---------------------- |
| Dependency updates | Weekly | Dependabot |
| Security scanning | On each PR | GitHub Actions |
| Secret rotation | Quarterly | GitHub Secrets |
| Access review | Monthly | Settings -\> Access |
| License compliance | Per dependency | License checker |
</details>
## Useful GitHub Features
### Keyboard Shortcuts
* Press `?` on any page to see shortcuts
* `t` - File finder
* `w` - Switch branches
* `s` - Search
* `g n` - Go to notifications
* `g i` - Go to issues
### Markdown Support
GitHub supports Markdown with extras:
* Task lists: `- [ ] Task`
* Tables
* Syntax highlighting
* Emoji :emoji:
* @mentions
* Issue/PR references: `#123`
### GitHub CLI
Install GitHub CLI for command-line access:
```bash
# Install (macOS)
brew install gh
# Authenticate
gh auth login
# Create repository
gh repo create my-repo --public
# Create issue
gh issue create --title "Bug report"
# Create pull request
gh pr create --title "Add feature"
```
## Collaboration Features
### Pull Request Workflow
Professional teams use pull requests for all changes:
1. **Fork or Branch**: Create feature branch from main
2. **Develop**: Make changes in isolated environment
3. **Push**: Upload changes to GitHub
4. **Open PR**: Create pull request with description
5. **Review**: Team reviews code, suggests changes
6. **CI/CD**: Automated tests run
7. **Merge**: Approved changes merged to main
### Code Review Best Practices
* Review for logic, not just syntax
* Be constructive and specific
* Use inline comments for context
* Approve, request changes, or comment
* Use suggestions for quick fixes
* Link to documentation when needed
> **:bulb: :bulb: Pro Tip**
> Use GitHub's review features: mark files as viewed, use batch comments, and create review checklists. Many teams require at least two approvals before merging critical changes.
### Contributing to Open Source
#### Finding Projects
1. **GitHub Explore**: Discover trending projects
2. **Good First Issues**: Look for `good-first-issue` label
3. **Up For Grabs**: Visit upforgrabs.net
4. **Your Stack**: Contribute to tools you use daily
#### Contribution Process
1. **Read Contributing Guidelines**: Every project is different
2. **Check Existing Issues**: Avoid duplicate work
3. **Fork the Repository**: Create your copy
4. **Create Feature Branch**: `git checkout -b feature/your-feature`
5. **Make Changes**: Follow project standards
6. **Test Thoroughly**: Run all tests locally
7. **Submit PR**: Reference related issues
8. **Respond to Feedback**: Be patient and professional
#### Open Source Etiquette
* Read documentation before asking questions
* Search existing issues before creating new ones
* Follow the project's code of conduct
* Start small with documentation or bug fixes
* Be patient - maintainers are often volunteers
* Say thank you - appreciation goes a long way
<details>
<summary>:emoji: Quick Reference: PR Description Template</summary>
```markdown
## Description
Brief description of changes
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## Testing
- [ ] Tests pass locally
- [ ] Added new tests
- [ ] Updated documentation
## Related Issues
Closes #123
## Screenshots (if applicable)
```
</details>
## Exploring GitHub
### Discovering Projects
* **GitHub Explore**: Trending repositories by language and time
* **Topics**: Browse curated collections
* **Advanced Search**: Use qualifiers like `stars:>1000 language:python`
* **GitHub Stars**: Organize starred repos into lists
* **GitHub Trending**: See what's popular daily/weekly/monthly
### Professional Networking
* Follow influential developers in your field
* Star repositories to bookmark and show appreciation
* Watch repositories for all activity notifications
* Fork to propose changes or create variants
* Sponsor developers and projects you depend on
* Join GitHub Discussions in projects you care about
## :warning: Common Issues & Solutions
### Authentication Problems
**Issue:** "Support for password authentication was removed"
**Solution:**
1. Generate a Personal Access Token (PAT)
2. Use PAT instead of password
3. Consider switching to SSH authentication
**Prevention:** Set up SSH keys or GitHub CLI for seamless authentication
### Push Rejected
**Issue:** "Updates were rejected because the remote contains work"
**Solution:**
```bash
# Fetch and merge remote changes
git pull origin main
# Or rebase for cleaner history
git pull --rebase origin main
# Then push again
git push origin main
```
**Prevention:** Always pull before starting new work
### Large File Errors
**Issue:** "This exceeds GitHub's file size limit of 100MB"
**Solution:**
1. Remove file from history: `git filter-branch`
2. Use Git LFS for large files
3. Add to .gitignore
**Prevention:** Configure .gitignore properly, use Git LFS for media files
### Permission Denied
**Issue:** "Permission denied (publickey)"
**Solution:**
1. Check SSH key: `ssh -T git@github.com`
2. Generate new key if needed
3. Add key to GitHub account
**Prevention:** Test SSH connection after setup
### Merge Conflicts
**Issue:** Conflicts when merging pull requests
**Solution:**
1. Pull latest changes
2. Resolve conflicts locally
3. Test merged code
4. Push resolved changes
**Prevention:** Keep branches small and focused, merge frequently
## Summary
GitHub transforms Git from a local version control system into a powerful collaboration platform. You've learned how to:
* Create and manage professional GitHub repositories
* Connect local and remote repositories securely
* Use advanced GitHub features for collaboration
* Follow industry best practices
* Contribute to open source projects
* Troubleshoot common issues
## :emoji: Hands-On Exercise: Setting Up a Professional Repository
**Challenge:** Create a production-ready repository for a sample project
**Requirements:**
1. Professional repository setup
* Descriptive name and comprehensive README
* Appropriate .gitignore and license
* Branch protection rules
* Issue and PR templates
2. Documentation
* README with badges
* CONTRIBUTING.md guide
* CODE\_OF\_CONDUCT.md
* Clear API documentation (if applicable)
3. Automation
* GitHub Actions workflow for CI
* Automated security scanning
* Dependabot configuration
4. Collaboration Features
* Create at least 3 issues with different labels
* Open a pull request with proper description
* Set up project board for task tracking
**Starter Template:**
```bash
# Create local repository
mkdir professional-project && cd professional-project
git init
# Create initial files
echo "# Professional Project" > README.md
echo "node_modules/" > .gitignore
echo "# Contributing Guidelines" > CONTRIBUTING.md
# Set up git
git add .
git commit -m "feat: initial repository setup"
# Create GitHub repo using CLI
gh repo create professional-project --public --source=. --remote=origin --push
```
<details>
<summary>:bulb: Solution Checklist</summary>
* [ ] Repository has professional README with badges
* [ ] Branch protection enabled on main
* [ ] Issue templates for bugs and features
* [ ] PR template with checklist
* [ ] GitHub Actions workflow running
* [ ] Security features enabled
* [ ] CODEOWNERS file configured
* [ ] Project board created
* [ ] Contributing guidelines clear
* [ ] License chosen and added
</details>
## :books: Additional Resources
### Official Documentation
* **GitHub Docs**: [docs.github.com](https://docs.github.com) - Comprehensive official documentation
* **GitHub Skills**: [skills.github.com](https://skills.github.com) - Interactive learning modules
* **GitHub CLI Manual**: [cli.github.com/manual](https://cli.github.com/manual) - Command-line interface guide
### Video Tutorials
* **GitHub's Official YouTube**: In-depth feature tutorials
* **The Net Ninja - Git & GitHub**: Beginner-friendly video series
* **Traversy Media - GitHub Crash Course**: Quick comprehensive overview
### Advanced Topics
* **GitHub Actions**: Automate workflows and CI/CD
* **GitHub API**: Build integrations and tools
* **GitHub Apps**: Create powerful automations
* **GitHub Enterprise**: Scale for large organizations
### Community Resources
* **Awesome GitHub**: Curated list of GitHub resources
* **GitHub Community Forum**: Ask questions and share knowledge
* **Dev.to #github**: Articles and discussions
* **Stack Overflow**: Troubleshooting help
## Next Steps
Now that you understand GitHub fundamentals and professional workflows, you're ready to master branching and merging strategies - essential skills for team collaboration and managing complex projects!