Question #113MediumTools & DevOps

Github Questions

#git

Answer

Overview

GitHub is a web-based platform for hosting Git repositories, enabling collaboration, code review, CI/CD, and project management.


Common GitHub Interview Questions

1. Git Workflow (Branching Strategy)

bash
# Feature branch workflow
git checkout main
git pull origin main
git checkout -b feature/user-auth  # Create feature branch
# ... make changes ...
git add .
git commit -m "feat: add user authentication"
git push origin feature/user-auth
# Create Pull Request → Review → Merge

2. Pull Request (PR) Process

text
1. Create feature branch from main
2. Make changes + commit
3. Push branch to GitHub
4. Open Pull Request (PR) on GitHub
5. Team reviews code → suggests changes
6. Address feedback → update PR
7. Approvals received → Merge to main
8. Delete feature branch

3. Git Rebase vs Merge

bash
# Merge — preserves history, creates a merge commit
git checkout main && git merge feature-branch
# Result: non-linear history with merge commits

# Rebase — replays commits on top, linear history
git checkout feature-branch && git rebase main
# Result: clean linear history, no merge commits
MergeRebase
HistoryNon-linear (merge commits)Linear
SafetySafe on shared branches⚠️ Don't rebase shared branches
Use whenMerging feature to mainKeeping branch up to date

4. Git Commands Reference

bash
git init                          # Initialize repo
git clone <url>                   # Clone remote repo
git status                        # Show changes
git add .                         # Stage all changes
git commit -m "message"           # Commit staged changes
git push origin branch-name       # Push to remote
git pull origin main              # Fetch + merge from remote
git fetch                         # Fetch without merging
git log --oneline                 # Short commit history
git diff                          # Show unstaged changes
git stash                         # Temporarily save changes
git stash pop                     # Restore stashed changes
git reset --soft HEAD~1           # Undo last commit (keep changes staged)
git reset --hard HEAD~1           # Undo last commit (discard changes)
git cherry-pick <commit-hash>     # Apply specific commit to current branch

5. GitHub Actions (CI/CD)

yaml
# .github/workflows/flutter.yml
name: Flutter CI
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: subosito/flutter-action@v2
        with:
          flutter-version: '3.x'
      - run: flutter pub get
      - run: flutter analyze
      - run: flutter test
      - run: flutter build apk --release

6. .gitignore for Flutter

gitignore
# Flutter/Dart
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
build/
*.iml

# Android
android/.gradle
android/local.properties
android/key.properties  # ← Never commit signing keys!

# iOS
ios/Pods/
ios/.symlinks/

Git Best Practices

PracticeWhy
Commit often with clear messagesEasy to review and revert
Use conventional commits (
text
feat:
,
text
fix:
,
text
chore:
)
Automated changelogs
Never commit secrets/keysSecurity risk
Squash commits before mergingClean history
Always branch from main/developSafe isolation
Code review all PRsCatch bugs early

Conventional Commits:

text
feat:
(new feature),
text
fix:
(bug fix),
text
chore:
(maintenance),
text
docs:
(documentation),
text
refactor:
(code change),
text
test:
(tests)