Blog/DevOps/GitHub

GitHub

6 essential github interview questions

Git Merge: combines changes from one branch into another. Workflow: 1. Create a feature branch and make changes. 2. Commit changes on feature branch. 3. Switch to main branch: git checkout main. 4. Merge: git merge feature-branch. 5. Git creates a new merge commit that combines both branches. Result: all changes from feature branch are now in main branch. Merge commit shows the merge happened. Use merge when you want to preserve branch history and clearly show when branches were integrated.
Git Rebase: re-applies your branch commits on top of another branch. Workflow: 1. Created feature branch and made changes. 2. Main branch got new commits (others pushed code). 3. You want your changes to appear on top of latest code. 4. Run: git rebase main. 5. Git temporarily removes your changes, pulls latest from main, then re-applies your changes on top. Result: your commits appear on top in history (linear history). Difference from Merge: Merge creates a merge commit and preserves branch history. Rebase rewrites history and keeps it linear. Use rebase for cleaner history when working on features before merging to main.
Git Reset: moves the branch HEAD pointer to a specific commit. Useful when you want to undo commits. Three modes: 1. Hard Reset 👉 git reset --hard commit-hash Moves HEAD to that commit. ALL changes after that commit are DELETED. Working directory is cleared. Use when you want to completely discard changes. WARNING: Data loss! 2. Soft Reset 👉 git reset --soft commit-hash Moves HEAD to that commit. Changes are NOT deleted, they stay in the staging area (index). Use when you want to undo a commit but keep the work and re-commit it properly. 3. Mixed Reset 👉 git reset --mixed commit-hash (default) Moves HEAD to that commit. Changes are kept in working directory but NOT staged. Use when you want to undo commits and the staging area, but keep your changes to re-work them.
Use Git Merge: When you want to preserve complete branch history and show integrations clearly. For long-running feature branches. When collaborating and other developers have the branch. Creates a merge commit which documents the merge point. Use Git Rebase: For cleaner, linear history before merging to main. When you want your commits to appear on top of latest code. On local branches before pushing (don't rebase public/shared branches). Interactive rebase for squashing commits. Rule: Rebase locally, Merge to public branches. Don't rebase commits that are already published to avoid conflicts with teammates.
Git Cherry-pick: selectively apply specific commits from one branch to another. Useful when you want only certain commits, not the entire branch. Workflow: 1. Identify commit hash: git log feature-branch. 2. Switch to target branch: git checkout main. 3. Cherry-pick: git cherry-pick commit-hash. 4. Git applies that specific commit to current branch. Creates a new commit with the same changes. Use cases: Apply bugfix from one branch to multiple branches. Pick specific features without entire branch merge. Selective backports to older versions.
Git Branches: parallel development lines. Main branch: production-ready code. Feature branches: develop new features (git checkout -b feature-name). Bugfix branches: fix bugs (git checkout -b bugfix-name). Create: git branch branch-name. Switch: git checkout branch-name. Delete: git branch -d branch-name. List: git branch. Naming convention: feature/user-auth, bugfix/payment-issue. Branch strategy: Git Flow (develop, release, main), GitHub Flow (main, feature branches). Branches allow parallel work and isolation of changes.