Git-interview-Question-set-3

Advanced Git Operations: Optimizing Operations and Collaboration | Question Set -3

5 minutes, 0 seconds Read
  1. What is interactive rebase in Git and how do you initiate it?
    • Answer: Interactive rebase in Git allows you to modify, reorder, or squash commits interactively before applying them to a new base commit. You can initiate it by running the command
      git rebase -i <base_commit>.
  2. Explain the purpose of the git reflog command.
    • Answer: The git reflog command displays a log of reference updates in the repository, including commit and branch changes, even if the commit history has been modified or deleted. It’s useful for recovering lost commits or branches.
  3. How do you cherry-pick a commit in Git?
    • Answer: You can cherry-pick a commit in Git using the command
      git cherry-pick <commit_hash>,
      where <commit_hash> is the hash of the commit you want to apply.
  4. What is a Git submodule and how do you add one to a repository?
    • Answer: A Git submodule is a repository embedded within another repository as a submodule reference. You can add a submodule to a repository using the command
      git submodule add <repository_url>.
  5. How do you squash multiple commits into a single commit in Git?
    • Answer: You can squash multiple commits into a single commit in Git using interactive rebase. Initiate an interactive rebase with
      git rebase -i <base_commit>,
      then change the commits you want to squash from “pick” to “squash” or “fixup” in the rebase editor.
  6. Explain the purpose of Git hooks and give an example of a hook.
    • Answer: Git hooks are scripts that Git executes before or after certain Git actions.
      They can be used to automate tasks such as linting code before committing.
      An example of a hook is the pre-commit hook, which runs before a commit is created.
  7. How do you revert a commit that has already been pushed to a remote repository?
    • Answer: You can revert a commit that has already been pushed to a remote repository by creating a new commit that undoes the changes introduced by the original commit using
      git revert <commit_hash>.
  8. What is Git bisect and how do you use it to find a bug?
    • Answer: Git bisect is a binary search tool used to find the commit that introduced a bug by systematically testing commits between a known good commit and a known bad commit.
      You can initiate it
      git bisect start
      and mark commits as good or bad until the faulty commit is found.
  9. How do you squash commits across multiple branches in Git?
    • Answer: You can squash commits across multiple branches in Git by rebasing one branch onto another and using interactive rebase to squash the desired commits.
  10. Explain the purpose of Git rebase with the --onto option.
    • Answer: Git rebase with the --onto option allows you to rebase a range of commits onto a new base commit, providing more control over the rebase operation. It’s useful for moving or combining commits onto different branches or starting points.
  11. What is a pull request in Git and how does it facilitate collaboration?
    • Answer: A pull request in Git is a request to merge changes from one branch into another.
      It facilitates collaboration by allowing team members to review, discuss, and suggest changes to the proposed changes before they are merged into the target branch.
  12. How do you create a pull request on GitHub/GitLab using the command line?
    • Answer: You can create a pull request on GitHub/GitLab using the command line by pushing your changes to a remote branch and then navigating to the repository’s website to create the pull request, or by using the GitHub/GitLab API with tools like hub or gitlab-cli.
  13. Explain the difference between forking and cloning a repository.
    • Answer: Forking a repository creates a copy of the repository under your own account on the hosting platform, allowing you to make changes independently. Cloning a repository creates a local copy of the repository on your own machine.
  14. How do you sync a forked repository with the original repository’s changes?
    • Answer: You can sync a forked repository with the original repository’s changes by adding the original repository as a remote using
      git remote add upstream <original_repo_url>
      and then fetching and merging changes from the upstream repository.
  15. What is a code review in the context of Git collaboration?
    • Answer: A code review is a process where team members review proposed changes to a codebase, typically through a pull request, to ensure quality, correctness, and adherence to coding standards.
  16. How do you resolve merge conflicts in a pull request?
    • Answer: Merge conflicts in a pull request can be resolved by either manually editing the conflicting files to remove the conflicts or by rebasing the branch on top of the target branch to resolve conflicts before creating the pull request.
  17. What is the purpose of branch protection rules in Git hosting platforms?
    • Answer: Branch protection rules in Git hosting platforms allow repository administrators to enforce certain restrictions and requirements on branches, such as requiring pull request reviews, status checks, or preventing force pushes.
  18. How do you squash commits in a pull request before merging?
    • Answer: Commits in a pull request can be squashed before merging by using the “squash and merge” option provided by the Git hosting platform or by squashing commits locally and force-pushing the changes to the pull request branch.
  19. Explain the concept of Git workflows (e.g., Gitflow, GitHub flow).
    • Answer: Git workflows define a set of rules and conventions for how changes are proposed, reviewed, and integrated into a codebase using Git.
      Examples include Gitflow, which defines separate branches for feature development, release preparation, and hotfixes, and GitHub flow, which emphasizes small, frequent releases through continuous integration and deployment.
  20. How do you revert a pull request that has already been merged?
    • Answer: To revert a pull request that has already been merged, you can create a new pull request that reverts the changes introduced by the original pull request, or manually revert the changes locally and push the revert commit to the repository.
author

Kartik Kocher

👋 Namaste! I'm Kartik Kocher, a Senior Cloud DevOps Engineer with over 8 years of experience in AWS cloud and DevOps. I'm passionate about delivering innovative cloud solutions, specializing in CI/CD pipelines, infrastructure automation, containerization, and cloud security. I've worked across various sectors, bringing efficiency through new products and services. Proficient in Jenkins, GitHub, AWS CodeBuild, and CodeDeploy for CI/CD pipelines, and adept at Kubernetes deployments on AWS EKS. Skilled in Terraform for infrastructure as code (IaC) practices. Security-focused with expertise in IAM roles, security groups, and compliance checks. Certified as an AWS Certified DevOps Engineer - Professional and AWS Certified Solutions Architect. I've led projects like migrating on-premises workloads to AWS and Azure, optimizing costs, and implementing CI/CD pipelines. Committed to following AWS best practices and contributing to the tech community through knowledge sharing and blogging. Reach out at me@kartikkocher.com or visit my website https://www.kartikkocher.com for collaboration or to connect. Tech enthusiast. Cloud explorer. Innovator. Let's connect and explore the endless possibilities in the cloud domain together! 🚀

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

X