Github Interview Questions And Answers

1. What is GitHub? How is it different from Git?

πŸ‘‰ Answer:

  • Git is a distributed version control system used to track code changes.
  • GitHub is a cloud-based platform that hosts Git repositories and adds collaboration features.

πŸ‘‰ Use Case:
In a team project, developers use Git locally and push code to GitHub for collaboration, reviews, and CI/CD.


2. What is a Repository?

πŸ‘‰ Answer:
A repository (repo) is a storage space for your project that contains code, files, and version history.

πŸ‘‰ Use Case:
You create a repo for a Playwright automation project where all test scripts, configs, and reports are stored.


3. What is the difference between Fork and Clone?

πŸ‘‰ Answer:

  • Fork: Copy of someone else’s repo into your GitHub account.
  • Clone: Copy of a repo to your local machine.

πŸ‘‰ Use Case:

  • Fork: Contributing to open-source.
  • Clone: Working on your team project locally.

4. What is a Branch?

πŸ‘‰ Answer:
A branch is a separate line of development.

πŸ‘‰ Use Case:
You create:

  • main β†’ production code
  • feature/login-test β†’ new feature work

5. What is a Pull Request (PR)?

πŸ‘‰ Answer:
A PR is a request to merge changes from one branch to another.

πŸ‘‰ Use Case:
QA automation engineer raises a PR after adding test cases β†’ Developer reviews β†’ merges into main.


6. What is Merge Conflict?

πŸ‘‰ Answer:
Occurs when Git cannot automatically merge changes.

πŸ‘‰ Use Case:
Two developers modify the same file β†’ conflict β†’ manually resolved before merge.


7. What is GitHub Actions?

πŸ‘‰ Answer:
A CI/CD tool in GitHub used to automate workflows.

πŸ‘‰ Use Case:

  • Run Playwright tests automatically on every PR
  • Deploy app after merge

8. What is .gitignore?

πŸ‘‰ Answer:
A file that specifies which files Git should ignore.

πŸ‘‰ Use Case:
Ignore:

  • node_modules/
  • test-results/
  • .env

9. What is Git Workflow (Branching Strategy)?

πŸ‘‰ Answer:
A process defining how teams use branches.

πŸ‘‰ Common strategies:

  • Git Flow
  • Feature Branch Workflow

πŸ‘‰ Use Case:

  • Create feature branch
  • Push code
  • Raise PR
  • Review β†’ Merge

10. What is Staging in Git?

πŸ‘‰ Answer:
Intermediate area before committing changes.

πŸ‘‰ Commands:

git add .
git commit -m "message"

πŸ‘‰ Use Case:
You selectively add only required files before committing.


11. Difference between Commit and Push?

πŸ‘‰ Answer:

  • Commit: Save changes locally
  • Push: Upload changes to GitHub

πŸ‘‰ Use Case:
You commit multiple times locally β†’ push once after testing.


12. What is Rebase vs Merge?

πŸ‘‰ Answer:

  • Merge: Keeps history (creates merge commit)
  • Rebase: Rewrites history (linear)

πŸ‘‰ Use Case:
Rebase keeps clean commit history before merging feature branch.


13. What is Tag in Git?

πŸ‘‰ Answer:
A tag marks a specific version of code.

πŸ‘‰ Use Case:
Mark releases like:

v1.0
v2.0

14. What is Git Stash?

πŸ‘‰ Answer:
Temporarily saves uncommitted changes.

πŸ‘‰ Use Case:
You are working on a feature but need to switch branches quickly.


15. What is Code Review in GitHub?

πŸ‘‰ Answer:
Process of reviewing code before merging.

πŸ‘‰ Use Case:

  • Developer checks logic
  • QA verifies test coverage
  • Ensures code quality

πŸ”Ή Scenario-Based GitHub Interview Questions


16. You pushed wrong code to main branch. What will you do?

πŸ‘‰ Answer:

  • Revert commit:
git revert <commit-id>

OR

  • Reset (if safe):
git reset --hard HEAD~1

πŸ‘‰ Best Practice:
Avoid direct commits to main β†’ use PR workflow.


17. Multiple developers working on same feature. How to manage?

πŸ‘‰ Answer:

  • Use feature branches
  • Regularly pull latest changes
  • Resolve conflicts early

πŸ‘‰ Use Case:
Each dev works on sub-features β†’ merged via PR.


18. How do you handle large files in GitHub?

πŸ‘‰ Answer:
Use Git LFS (Large File Storage).

πŸ‘‰ Use Case:
Store large test data or binaries.


19. How do you secure sensitive data in GitHub?

πŸ‘‰ Answer:

  • Never commit secrets
  • Use GitHub Secrets
  • Use .gitignore

πŸ‘‰ Use Case:
Store API keys in environment variables.


20. Explain CI/CD pipeline using GitHub Actions

πŸ‘‰ Answer:

  1. Code pushed to GitHub
  2. Workflow triggers
  3. Build runs
  4. Tests execute
  5. Deploy

πŸ‘‰ Use Case:
Playwright tests run automatically on every commit.


πŸ”Ή Advanced Practical Questions


21. How do you revert a specific file to previous version?

git checkout <commit-id> -- file.js

22. How do you squash commits?

git rebase -i HEAD~3

πŸ‘‰ Combine multiple commits into one.


23. What is Detached HEAD?

πŸ‘‰ Answer:
When you’re not on any branch.

πŸ‘‰ Use Case:
Checking old commit without affecting current branch.


24. How do you delete a branch?

git branch -d branch-name
git push origin --delete branch-name

25. What is Upstream in Git?

πŸ‘‰ Answer:
Reference to original repository (especially in forks).

πŸ‘‰ Use Case:
Keep your fork updated with original repo.


Mock Interview: GitHub (Real Company Style)


πŸ”Ή Round 1: Basics + Practical Understanding

❓ Q1: Explain your GitHub workflow in your current project.

πŸ‘‰ Strong Answer:

β€œWe follow a feature branch workflow. Each task starts with a new branch from main. After development, we push code and raise a pull request. CI runs automatically using GitHub Actions. After code review and approvals, we merge into main. Direct commits to main are restricted.”

πŸ‘‰ What interviewer checks:

  • Real experience
  • Collaboration understanding
  • CI/CD awareness

❓ Q2: What happens when you run git push?

πŸ‘‰ Strong Answer:

β€œIt uploads local commits from my machine (using Git) to the remote repository on GitHub, making them available to the team.”

πŸ‘‰ Follow-up trap:
πŸ‘‰ β€œWhat if push is rejected?”

βœ”οΈ Answer:

β€œIt usually means my branch is behind. I pull the latest changes, resolve conflicts if any, and push again.”


πŸ”Ή Round 2: Scenario-Based Questions


❓ Q3: You and another developer changed the same file. Your PR shows conflict. What do you do?

πŸ‘‰ Strong Answer:

β€œI pull the latest changes from main, resolve conflicts locally, test the code, commit the fix, and push again to update the PR.”

πŸ‘‰ Bonus point:
Mention testing after conflict resolution.


❓ Q4: You accidentally pushed sensitive data (API key) to GitHub. What will you do?

πŸ‘‰ Strong Answer:

β€œFirst, I revoke the key immediately. Then I remove it from the repository, rewrite history if needed, and ensure it’s added to .gitignore. Going forward, I store secrets using GitHub Secrets.”

πŸ‘‰ What interviewer checks:

  • Security awareness
  • Real-world handling

❓ Q5: Your teammate’s PR broke the build. What should happen?

πŸ‘‰ Strong Answer:

β€œThe CI pipeline should fail automatically. The PR should not be merged until the issue is fixed. We enforce required checks before merging.”

πŸ‘‰ Extra credit:
Mention branch protection rules.


πŸ”Ή Round 3: CI/CD + Automation (Very Important)


❓ Q6: How do you integrate automation tests with GitHub?

πŸ‘‰ Strong Answer:

β€œWe use GitHub Actions to trigger Playwright tests on every PR. The workflow installs dependencies, runs tests, and publishes reports.”

πŸ‘‰ Example flow:

  • PR created
  • Tests run automatically
  • Pass β†’ merge allowed
  • Fail β†’ fix required

❓ Q7: How do you ensure code quality before merging?

πŸ‘‰ Strong Answer:

β€œWe use a combination of:

  • Pull request reviews
  • Automated tests
  • Linting checks
  • CI validation

Only after all checks pass, the PR is merged.”


πŸ”Ή Round 4: Advanced Problem Solving


❓ Q8: Your main branch is broken after a merge. What will you do?

πŸ‘‰ Strong Answer:

β€œI would quickly identify the faulty commit and revert it using git revert. Then fix the issue in a new branch and raise another PR.”

πŸ‘‰ Important:
Avoid rewriting history in shared branches.


❓ Q9: How do you handle multiple environments (dev, staging, prod)?

πŸ‘‰ Strong Answer:

β€œWe use different branches or deployment workflows. For example:

  • develop β†’ dev environment
  • main β†’ production
    CI/CD pipelines deploy automatically based on branch.”

❓ Q10: How do you manage large teams working on the same repo?

πŸ‘‰ Strong Answer:

β€œWe use:

  • Feature branches
  • Clear naming conventions
  • Code owners
  • Mandatory PR reviews
  • CI/CD checks

This ensures smooth collaboration and avoids conflicts.”


πŸ”Ή Round 5: Rapid Fire (Quick Checks)


❓ Difference between Fork and Clone?

πŸ‘‰ Fork = copy on GitHub
πŸ‘‰ Clone = copy on local machine


❓ What is HEAD in Git?

πŸ‘‰ Pointer to the current commit/branch


❓ What is Rebase?

πŸ‘‰ Rewrites commit history to make it linear


❓ What is Stash?

πŸ‘‰ Temporarily saves uncommitted changes


❓ What is a Tag?

πŸ‘‰ Marks a release/version


πŸ”Ή Real Interview Challenge (Hands-On Thinking)


❓ Q11: Design a GitHub workflow for automation testing.

πŸ‘‰ Strong Answer:

β€œI would:

  1. Trigger workflow on PR and push
  2. Install dependencies
  3. Run Playwright tests
  4. Generate reports
  5. Upload artifacts
  6. Fail build if tests fail

This ensures only tested code gets merged.”


πŸ”Ή Final HR + Practical Question


❓ Q12: Tell me a real problem you faced in GitHub and how you solved it.

πŸ‘‰ Sample Answer:

β€œWe had frequent merge conflicts due to long-running branches. I suggested smaller PRs and frequent rebasing. This reduced conflicts and improved deployment speed.”



Leave a Comment