git_workflow_deployment 16 Q&As

Git Workflow Deployment FAQ & Answers

16 expert Git Workflow Deployment answers researched from official documentation. Every answer cites authoritative sources you can verify.

unknown

16 questions
A

Use git pull to fetch and merge remote changes. Basic: git pull origin main fetches changes from origin/main and merges into current branch. Safe workflow: (1) Commit or stash local changes first: git stash, (2) Pull: git pull origin main, (3) Apply stash if needed: git stash pop. Pull with rebase (linear history): git pull --rebase origin main avoids merge commits, rebases local commits on top of remote. Fetch only (inspect before merge): git fetch origin then git diff origin/main to see changes, git merge origin/main to merge manually. Pull all branches: git pull --all. Handle conflicts: git pull may cause conflicts, resolve with git mergetool, then git commit. Best practices: (1) Pull before starting work, (2) Commit local changes before pull, (3) Use --rebase for cleaner history, (4) Review changes with git log after pull. Auto-setup tracking: git branch --set-upstream-to=origin/main main then git pull without arguments. Avoid: pulling with uncommitted changes (can lose work).

99% confidence
A

Prevent conflicts with small, frequent merges and communication. Strategies: (1) Keep branches short-lived (<3 days), merge frequently to minimize divergence, (2) Pull main regularly: git checkout feature && git pull origin main keeps feature updated, (3) Coordinate with team on file ownership, avoid simultaneous edits, (4) Use feature flags for incomplete features, merge early without exposing to users. Merge workflow: git checkout main && git pull && git merge feature --no-ff (creates merge commit for history). Fast-forward merge (linear): git merge feature --ff-only fails if not possible. Squash commits: git merge feature --squash combines all commits into one. When conflicts occur: git mergetool opens visual editor (VS Code, kdiff3), resolve markers (<<<<<<, ======, >>>>>>>), git add resolved files, git commit. Prevention tools: (1) Git hooks to check formatting before commit, (2) Code formatters (Prettier, ESLint --fix) for consistent style, (3) Feature flags to isolate changes. Statistics: 70% of developers encounter conflicts regularly (2025), 80% resolve with merge tools. Best practice: trunk-based development with short-lived branches (28% faster delivery).

99% confidence
A

Delete remote branches with git push --delete after merge. Delete single branch: git push origin --delete feature-branch. Delete multiple: git push origin --delete feature-1 feature-2. Verify branch merged first: git branch --merged lists merged branches (safe to delete), git branch --no-merged shows unmerged (risky). Workflow: (1) Merge PR on GitHub/GitLab, (2) Delete remote: git push origin --delete feature-branch, (3) Delete local tracking: git branch -d feature-branch (lowercase -d fails if unmerged, uppercase -D force deletes). Auto-delete on merge: GitHub/GitLab settings enable 'Automatically delete head branches' after PR merge. Bulk delete merged branches: git branch --merged | grep -v main | xargs git branch -d deletes all local merged branches except main. Clean stale remote refs: git fetch --prune removes deleted remote branches from local tracking. Best practices: (1) Delete branches after merge to reduce clutter, (2) Use PR auto-delete for consistency, (3) Keep only active branches, (4) Document long-lived branches (release, hotfix).

99% confidence
A

Use git fetch --prune to remove deleted remote branches from local tracking. Command: git fetch --prune origin removes refs for branches deleted on origin. List stale refs before cleanup: git remote prune origin --dry-run shows what will be deleted. Auto-prune on fetch: git config --global fetch.prune true enables automatic pruning on every git fetch. Manual prune: git remote prune origin cleans without fetching. What it does: removes local refs to remote branches that no longer exist (e.g., refs/remotes/origin/deleted-branch), doesn't delete local branches, only tracking refs. Why needed: after teammates delete remote branches, local repo still tracks them as origin/branch-name, fetch --prune syncs local tracking with remote state. Verify cleanup: git branch -r lists remaining remote-tracking branches. Best practices: (1) Enable fetch.prune globally, (2) Run git fetch --prune weekly on active projects, (3) Combine with local branch cleanup: git branch -d $(git branch --merged), (4) Educate team to delete branches after merge. Alternative: git remote update --prune fetches all remotes and prunes.

99% confidence
A

Non-fast-forward error occurs when remote has commits you don't have locally. Error: ! [rejected] main -> main (non-fast-forward). Solution workflow: (1) Pull first: git pull origin main --rebase (rebases your commits on top of remote), (2) Resolve conflicts if any, (3) Push: git push origin main. Alternative with merge: git pull origin main (creates merge commit), git push origin main. Why it happens: teammate pushed while you were working, your local main is behind remote. Force push (dangerous): git push --force origin main overwrites remote history, ONLY use on personal branches, NEVER on shared branches (main, develop), destroys teammates' work. Safe force push: git push --force-with-lease origin main fails if remote changed since last fetch, protects against accidental overwrites. Prevention: (1) Pull before starting work, (2) Use feature branches (not main directly), (3) Communicate with team before force push, (4) Enable branch protection rules (require PR, disable force push). Best practice: git pull --rebase keeps linear history, easier to read than merge commits. Never: git push --force on main/master.

99% confidence
A

Follow Conventional Commits format for consistency and automation. Format: (): with optional body/footer. Types: feat (new feature), fix (bug fix), docs (documentation), style (formatting), refactor (code restructuring), test (adding tests), chore (maintenance), perf (performance), ci (CI/CD changes). Examples: feat(auth): add OAuth2 login, fix(api): handle null user response, docs: update README with setup instructions. Best practices: (1) Use imperative mood: 'add feature' not 'added feature', (2) First line ≤50 chars, (3) Lowercase for conventional commits, (4) No period at end, (5) Body ≤72 chars per line (if needed). Breaking changes: feat!: drop support for Node 14 or footer: BREAKING CHANGE: Node 14 no longer supported. Benefits: auto-generate CHANGELOG, semantic versioning (feat = minor, fix = patch, ! = major), searchable history (git log --grep='feat'). Enforcement: use commitlint + husky to validate messages pre-commit. Template: git config commit.template ~/.gitmessage. Tools: Commitizen for interactive commit creation. Example with body: git commit -m 'feat(cart): add item quantity selector' -m 'Allows users to select 1-10 items in cart before adding.'

99% confidence
A

Git provides merge options for automatic conflict resolution. Options: (1) -X ours: git merge -X ours feature resolves conflicts by favoring current branch's changes while keeping non-conflicting changes from both sides, (2) -X theirs: git merge -X theirs feature favors incoming branch's changes on conflicts, (3) -X diff-algorithm=patience: uses slower but more accurate algorithm for complex conflicts (patience is deprecated as standalone option). Note: -X are strategy options, not strategies (-s). Use cases: -X ours when current branch is authoritative, -X theirs when feature branch should take precedence. Rerere (Reuse Recorded Resolution): git config --global rerere.enabled true remembers previous conflict resolutions (stored up to 60 days), auto-applies same resolution on similar conflicts, works automatically with git merge. Merge tools: git mergetool opens configured tool (VS Code, vimdiff, kdiff3) for visual conflict resolution, presents conflicts with markers (<<<<<<, ======, >>>>>>>). Custom merge drivers: define in .git/config with [merge "driver"] block, assign to files via .gitattributes (e.g., *.lock merge=ours). Prevention strategies: (1) Frequent small merges reduce divergence, (2) Code formatting automation (Prettier) eliminates style conflicts, (3) Feature flags enable early integration, (4) Trunk-based development with short-lived branches (<2 days). Best practice: use rerere for repeated conflicts, manually review logic conflicts even when auto-resolved, test thoroughly after merge.

99% confidence
A

Best practices vary by team size and deployment frequency. For modern CI/CD (2025 recommendation): (1) Trunk-based development: commit directly to main or use short-lived feature branches (<2 days), merge frequently (multiple times/day), use feature flags for incomplete features, 28% faster delivery than GitFlow. (2) Branch protection: require PR reviews, require status checks (tests, linting), prevent force push on main. (3) Small commits: atomic changes (one logical change per commit), descriptive messages (Conventional Commits), easy to review and revert. (4) Frequent integration: pull from main multiple times/day, merge back quickly, reduces conflict complexity. For scheduled releases: GitFlow with main (production), develop (integration), feature/, release/, hotfix/*. Small teams (<5): GitHub Flow - main + feature branches, PR for everything, deploy from main. Best practices all workflows: (1) Meaningful branch names (feature/user-auth not feature/123), (2) Clean history (squash or rebase), (3) Code reviews on all PRs, (4) Automated testing in CI, (5) Keep branches synced with main. Tool support: GitHub/GitLab branch protection, required status checks, auto-delete merged branches. 93.87% developers use Git (2025), trunk-based adoption growing.

99% confidence
A

Remote pruning removes stale references to deleted remote branches. Purpose: keeps local repo in sync with remote state, removes refs/remotes/origin/deleted-branch entries for branches deleted on remote, cleans up git branch -r output, prevents confusion about active branches. How it works: git fetch --prune queries remote for current branches, deletes local tracking refs that no longer exist remotely, doesn't delete local branches (only remote-tracking refs). Example scenario: teammate merges PR and deletes feature-x on GitHub, your local still shows origin/feature-x until you prune, git fetch --prune removes origin/feature-x reference. Enable auto-prune: git config --global fetch.prune true prunes on every fetch. Benefits: (1) Accurate view of remote branches, (2) Prevents accidentally checking out deleted branches, (3) Reduces clutter in branch lists, (4) Improves performance (fewer refs to manage). When to prune: after PRs merged and branches deleted remotely, weekly on active projects, before starting new features (see actual active branches). View stale refs: git remote prune origin --dry-run. Related: git branch --merged | xargs git branch -d cleans local merged branches.

99% confidence
A

Branching strategies define how teams organize code changes for collaboration and deployment. Purposes: (1) Parallel development: multiple features developed simultaneously without conflicts, (2) Stable main branch: production-ready code always in main/master, (3) Release management: organized process for versioning and deployment, (4) Hotfix handling: fast emergency fixes without disrupting development, (5) Code review: feature branches enable PR-based reviews before merge. Common strategies: (1) Trunk-based (2025 best practice): short-lived branches (<2 days), frequent merges to main, feature flags for incomplete features, 28% faster delivery, best for: CI/CD, microservices, small teams. (2) GitFlow (traditional): main (production), develop (integration), feature/, release/, hotfix/*, best for: scheduled releases, multiple production versions, large teams. (3) GitHub Flow (simple): main + feature branches, PR for everything, deploy from main, best for: web apps, continuous deployment, small teams. Key metrics: 70% developers encounter conflicts regularly, proper strategy reduces conflict rate by 40%. Choose based on: deployment frequency (continuous vs scheduled), team size, product maturity, regulatory requirements.

99% confidence
A

Create .github/workflows/deploy.yml for automated deployment. Basic workflow: name: Deploy; on: push: branches: [main]; jobs: build-deploy: runs-on: ubuntu-latest; steps: - uses: actions/checkout@v4; - uses: actions/setup-node@v4; with: node-version: '20'; - run: npm ci; - run: npm run build; - uses: peaceiris/actions-gh-pages@v3; with: github_token: ${{ secrets.GITHUB_TOKEN }}; publish_dir: ./dist;. Deploy to Firebase: use FirebaseExtended/action-hosting-deploy@v0 with firebaseServiceAccount: ${{ secrets.FIREBASE_TOKEN }};. Deploy to Vercel: use amondnet/vercel-action@v20. Best practices: (1) Run tests before deploy: npm run test:unit && npm run lint, (2) Cache node_modules: uses: actions/cache@v4; with: path: node_modules; key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }};, (3) Environment secrets: Settings → Secrets → Actions, reference with ${{ secrets.NAME }}, (4) Deploy previews on PRs: on: pull_request; environment: preview;. Matrix builds: test Node 18, 20, 22 in parallel. Notifications: send Slack/Discord message on success/failure. 2025 best practice: deploy preview for every PR, auto-deploy main to production.

99% confidence
A

Separate frontend (Vue) and backend (Laravel) builds in CI/CD pipeline. Architecture: Vue (SPA) served from CDN/static hosting, Laravel API on server (AWS, DigitalOcean). Pipeline steps: (1) Test: run backend tests (PHPUnit), run frontend tests (Vitest), lint both (PHP CS Fixer, ESLint); (2) Build: Laravel - composer install --no-dev --optimize-autoloader, php artisan config:cache, php artisan route:cache, Vue - npm ci, npm run build (creates dist/); (3) Deploy: Backend - rsync or SSH to server, run migrations (php artisan migrate --force), restart queues/workers, Frontend - upload dist/ to S3/Cloudflare Pages, invalidate CDN cache. GitHub Actions workflow: separate jobs for backend/frontend with dependencies: test → build → deploy. Environment variables: Laravel - .env on server (not in repo), Vue - .env.production with VITE_API_URL=${{ secrets.API_URL }}. Best practices: (1) Database migrations in deployment, rollback on failure, (2) Zero-downtime deploys (blue-green), (3) Health checks after deploy, (4) Separate staging and production workflows. Tools: Laravel Vapor (serverless), Envoyer (zero-downtime), GitHub Actions (free for public repos).

99% confidence
A

Configure workflow triggers in CI/CD for automatic deployments. GitHub Actions triggers: on: push: branches: [main]; deploys on every push to main, on: pull_request: types: [opened, synchronize]; deploys preview on PR updates, on: release: types: [published]; deploys on GitHub release creation, on: workflow_dispatch; manual trigger from UI, on: schedule: cron: '0 0 * * 0'; weekly deploys. Conditional deployments: if: github.ref == 'refs/heads/main' && github.event_name == 'push' only deploy main branch pushes. Environment-based: branches: [main] → production, branches: [staging] → staging environment, pull_request → preview environments. Tag-based: on: push: tags: ['v*']; deploys on version tags (v1.0.0). Best practices: (1) Main branch → auto-deploy to staging, (2) Tags → production deploys (requires approval), (3) PRs → preview environments (auto-delete after merge), (4) Manual production deploys via workflow_dispatch with approval gates. Approval gates: environment: production; with required reviewers in GitHub settings. Avoid: deploying on every commit to any branch (wastes resources), auto-deploy production without tests, deploying breaking changes without rollback plan.

99% confidence
A

Implement automated health checks and smoke tests post-deployment. Health check endpoint: create /api/health returning { status: 'ok', version: '1.2.3', timestamp: Date.now() }, query after deploy to verify service is up. Smoke tests: curl -f https://app.com/api/health || exit 1 in deployment script (fails pipeline if unhealthy), test critical paths (login, main page loads, API responds). GitHub Actions verification: steps: - run: npm run build; - run: npm run deploy; - name: Health Check; run: | for i in {1..10}; do curl -f https://app.com/health && break || sleep 10; done. Advanced checks: (1) Monitor response time: curl -w '%{time_total}' should be <500ms, (2) Check specific features: test user registration endpoint, verify database connectivity, (3) Lighthouse CI for performance regression, (4) Visual regression testing (Percy, Chromatic). Rollback triggers: if health check fails after 5 minutes, auto-rollback to previous version, alert team via Slack/PagerDuty. Monitoring integration: send deployment event to Datadog/New Relic, track error rate increase post-deploy, use APM to detect performance degradation. Best practice: combine health checks + smoke tests + monitoring alerts for comprehensive verification.

99% confidence
A

Implement fail-fast, notifications, and auto-retry strategies. Immediate actions: (1) Fail pipeline on first error: set -e in bash scripts, npm ci && npm run lint && npm test (stops at first failure), prevents wasting resources on subsequent steps. (2) Parallel jobs: run lint, test, type-check in parallel, fail entire workflow if any job fails. Notifications: send Slack/Discord message with failure details: uses: 8398a7/action-slack@v3; with: status: ${{ job.status }}; if: failure();. Include: commit message, author, failed step, logs link. Debugging: (1) GitHub Actions artifacts: upload build logs, screenshots from failed tests, uses: actions/upload-artifact@v4; with: name: test-results; path: test-results/;. (2) SSH debug session: use action-tmate for interactive debugging (careful with secrets). Auto-retry: uses: nick-invision/retry@v2; with: timeout_minutes: 10; max_attempts: 3; command: npm test; for flaky tests (network issues). Prevention: (1) Run tests locally pre-commit with husky, (2) Pre-commit hooks for linting, (3) Required status checks (can't merge if CI fails), (4) Branch protection rules. Best practices: fast feedback (<5 min builds), clear error messages, easy access to logs, automatic issue creation for repeated failures.

99% confidence
A

Automated deployments increase speed, reliability, and developer productivity. Key benefits: (1) Faster time-to-market: deploy multiple times/day vs weekly manual deploys, reduce release cycle from weeks to hours, enable continuous delivery (code to production in minutes). (2) Reduced human error: eliminate manual steps (forgot to run migrations, wrong environment variables), consistent process every time, automatic rollback on failure. (3) Improved reliability: automated tests before deploy (unit, integration, E2E), health checks verify successful deployment, blue-green deployments for zero downtime. (4) Better developer experience: developers focus on code not DevOps, preview environments for every PR, easy rollback to previous versions. (5) Audit trail: every deployment logged (who, when, what changed), git history provides complete change tracking, compliance requirements met automatically. (6) Cost savings: reduce DevOps manual work by 80%, catch bugs before production (cheaper to fix), optimize resource usage (auto-scale on deploy). Statistics: teams with CI/CD deploy 200× more frequently, 3× lower change failure rate (DORA metrics). Best practice: start with simple pipeline (test → build → deploy staging), gradually add complexity (multi-environment, approval gates, rollback automation).

99% confidence