Dev Logs
/Git & GitHub/ Security concern
Chapters
  • 01Git and GitHub Introduction
  • 02Basic Git Commands
  • 03Remote Repositories and GitHub
  • 04Branching Basics
  • 05Git Merge vs Rebase
  • 06Git Stash
  • 07Git Diff and Log
  • 08Resolving Merge Conflicts
  • 09Pull Requests and Code Review
  • 10Question about implementation
  • 11Positive feedback
  • 12Security concern
    • As a PR Author
    • Advanced PR Techniques
    • . Draft Pull Requests
    • . PR Templates
    • . Linking Issues
    • . Co-authored Commits
    • GitHub CLI for Pull Requests
    • Installation
    • Authentication
    • PR Commands
    • PR Best Practices
    • . Size and Scope
    • . Clear Descriptions
    • . Commit Organization
    • . Self-Review
    • Merge Strategies
    • . Merge Commit
    • . Squash and Merge
    • . Rebase and Merge
    • Automated Checks
    • . Status Checks
    • . Branch Protection Rules
    • Troubleshooting
    • PR Conflicts
    • Failed Checks
    • Accidental Force Push
    • Quick Reference
  • 13Forking and Upstream Remotes
  • 14Advanced Git Rebase
  • 15Git Cherry-pick
  • 16Git Reset Deep Dive
  • 17Git Reflog Recovery
  • 18Git Bisect Bug Hunting
  • 19Git Tags
  • 20Git Hooks
  • 21Add hooks to version control
  • 22Conventional Commits
  • 23Update README
  • 24Conventional Commits Demo
  • 25GitHub CLI (gh)
  • 26GitHub Actions Basics
  • 27Maintaining Clean Git History in Teams
  • 28Branching Strategies: Git Flow vs Trunk-Based Development
  • 29Force Push Safety: Using --force-with-lease
All chapters

Security concern

The project links are currently placeholder. When implementing real links, make sure to add rel="noopener" for external links.


**Avoid:**
- "This is wrong" → "Consider this alternative approach..."
- "Bad code" → "This could be improved by..."
- "Fix this" → "What do you think about..."

#### 3. Review Types

```bash
# Approve PR
"LGTM! Great work on the responsive design. The hover effects are a nice touch."

# Request changes
"The functionality looks good, but I have a few suggestions for code organization. Please see my inline comments."

# Comment only
"Nice implementation! I left a few optional suggestions for future improvements."

As a PR Author

1. Responding to Feedback

bash
# Address feedback with new commits
git checkout feature/add-projects-section

# Make requested changes
echo ":root { --spacing-lg: 2rem; }" >> style.css
sed -i 's/gap: 2rem/gap: var(--spacing-lg)/' style.css

# Commit improvements
git add style.css
git commit -m "Use CSS custom properties for consistent spacing

Addresses review feedback about maintainable spacing values."

# Push updates
git push origin feature/add-projects-section

2. Responding to Comments

markdown
> Why did you choose CSS Grid over Flexbox here?

Good question! I chose CSS Grid because:

1. It handles both rows and columns automatically
2. The `auto-fit` and `minmax()` functions provide better responsive behavior
3. It's more semantic for this card-based layout

Flexbox would work too, but would require more media queries for the responsive behavior.

Advanced PR Techniques

1. Draft Pull Requests

bash
# Create draft PR for early feedback
# On GitHub: Check "Create draft pull request"
# Or use GitHub CLI:
gh pr create --draft --title "WIP: Add projects section" --body "Early version for feedback"

2. PR Templates

Create .github/pull_request_template.md:

markdown
## Description

Brief description of changes

## Type of Change

- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update

## Testing

- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed

## Checklist

- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] No breaking changes (or documented)

## Screenshots (if applicable)

## Additional Notes

3. Linking Issues

markdown
## Description

Implements user authentication system

Closes #123
Fixes #456
Resolves #789

4. Co-authored Commits

bash
# When pair programming
git commit -m "Add user authentication

Co-authored-by: Jane Doe <jane@example.com>"

GitHub CLI for Pull Requests

Installation

bash
# Windows
winget install GitHub.cli

# macOS
brew install gh

# Linux
sudo apt install gh

Authentication

bash
# Login to GitHub
gh auth login

# Check status
gh auth status

PR Commands

bash
# Create PR
gh pr create --title "Add projects section" --body "Adds responsive projects showcase"

# Create draft PR
gh pr create --draft

# List PRs
gh pr list
gh pr list --state open
gh pr list --author @me

# View PR
gh pr view 123
gh pr view --web  # Open in browser

# Check out PR locally
gh pr checkout 123

# Review PR
gh pr review 123 --approve
gh pr review 123 --request-changes --body "Please fix the CSS issues"

# Merge PR
gh pr merge 123
gh pr merge 123 --squash
gh pr merge 123 --rebase

# Close PR
gh pr close 123

PR Best Practices

1. Size and Scope

bash
# Good: Small, focused PRs
git log --oneline main..feature/add-button  # 2-3 commits

# Avoid: Large, multi-purpose PRs
git log --oneline main..feature/redesign-everything  # 20+ commits

Guidelines:

  • < 400 lines changed: Easy to review
  • 400-1000 lines: Manageable but requires focus
  • > 1000 lines: Consider breaking into smaller PRs

2. Clear Descriptions

markdown
# Good PR Description

## What

Adds user authentication with JWT tokens

## Why

Users need to log in to access personalized features

## How

- Implemented login/logout endpoints
- Added JWT middleware for protected routes
- Created user registration flow

## Testing

- Added unit tests for auth functions
- Tested login flow manually
- Verified token expiration handling

3. Commit Organization

bash
# Before creating PR, clean up commits
git rebase -i HEAD~5

# Squash related commits
# Fix commit messages
# Remove debug commits

4. Self-Review

bash
# Review your own changes before creating PR
git diff main..feature/branch

# Check for:
# - Debug code left behind
# - TODO comments
# - Formatting issues
# - Missing documentation

Merge Strategies

1. Merge Commit

bash
# Creates merge commit preserving branch history
git checkout main
git merge feature/branch

Result:

*   a1b2c3d Merge pull request #123 from feature/branch
|\
| * d4e5f6g Add projects section
| * g7h8i9j Update navigation
|/
* j0k1l2m Previous commit

2. Squash and Merge

bash
# Combines all commits into single commit
# Available on GitHub PR interface

Result:

* a1b2c3d Add projects section (#123)
* j0k1l2m Previous commit

3. Rebase and Merge

bash
# Replays commits without merge commit
git checkout main
git rebase feature/branch

Result:

* d4e5f6g Add projects section
* g7h8i9j Update navigation
* j0k1l2m Previous commit

Automated Checks

1. Status Checks

yaml
# .github/workflows/pr-checks.yml
name: PR Checks
on:
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: "18"
      - name: Install dependencies
        run: npm install
      - name: Run tests
        run: npm test
      - name: Run linter
        run: npm run lint
      - name: Check formatting
        run: npm run format:check

2. Branch Protection Rules

bash
# Configure on GitHub:
# Settings → Branches → Add rule

# Require:
# - Status checks to pass
# - Up-to-date branches
# - Review from code owners
# - Signed commits

Troubleshooting

PR Conflicts

bash
# Update feature branch with latest main
git checkout feature/branch
git fetch origin
git rebase origin/main

# Resolve conflicts if any
# Push updated branch
git push --force-with-lease origin feature/branch

Failed Checks

bash
# Fix issues locally
npm run lint:fix
npm test

# Commit fixes
git add .
git commit -m "Fix linting issues"
git push origin feature/branch

Accidental Force Push

bash
# Check reflog for lost commits
git reflog

# Recover if needed
git reset --hard commit-hash
git push --force-with-lease origin feature/branch

Quick Reference

bash
# PR workflow
git checkout -b feature/branch    # Create feature branch
# ... make changes ...
git push -u origin feature/branch # Push to GitHub
# Create PR on GitHub interface

# GitHub CLI
gh pr create                      # Create PR
gh pr list                        # List PRs
gh pr checkout 123               # Checkout PR locally
gh pr review 123 --approve       # Approve PR
gh pr merge 123 --squash         # Merge PR

# Update PR
git add .
git commit -m "Address feedback"
git push origin feature/branch

# Clean up after merge
git checkout main
git pull origin main
git branch -d feature/branch

Previous: Merge Conflicts
Next: Forking and Upstream

PreviousPositive feedbackNextForking and Upstream Remotes

Open source, free forever. Built by iammhador.

Contribute on GitHub