Corporate Training
Request Demo
Click me
Menu
Let's Talk
Request Demo

Git and GitHub Interview Questions and Answers

by Pritha Radhakrishnan, on Aug 5, 2023 3:55:22 PM

Git-and-GitHub-Interview-Questions-and-Answers

Q1. What is Git?

Ans: Git is a distributed version control system that allows multiple developers to work on a project simultaneously, keeping track of changes in code.

Q2. What is GitHub?

Ans: GitHub is a web-based hosting service that uses Git for version control. It provides a platform for collaboration, code sharing, and project management.

Q3. What is the difference between Git and GitHub?

Ans: Git is the version control system itself, while GitHub is a web-based platform built around Git that provides additional collaboration features.

Q4. What are the advantages of using Git?

Ans: Git offers features such as decentralized development, easy branching and merging, version control, and offline capabilities.

Q5. How do you create a Git repository?

Ans: You can create a Git repository by using the "git init" command in the desired project directory.

Q6. What is a "commit" in Git?

Ans: A commit represents a snapshot of changes made to the repository. It is a way to save and track the progress of your work.

Q7. How do you create a new branch in Git?

Ans: To create a new branch, you can use the "git branch" command followed by the branch name, or use "git checkout -b" to create and switch to the new branch.

Q8. How do you merge branches in Git?

Ans: To merge branches, you can use the "git merge" command followed by the branch you want to merge into your current branch.

Q9. What is a "pull request" in GitHub?

Ans: A pull request is a way to propose changes from one branch to another in a GitHub repository. It allows for code review and collaboration before merging the changes.

Q10. How do you resolve a merge conflict in Git?

Ans: To resolve a merge conflict, you need to manually edit the conflicting files, remove conflict markers, and then commit the resolved changes.

Q11. What is the purpose of a ".gitignore" file?

Ans: The ".gitignore" file is used to specify files and directories that should be ignored by Git, preventing them from being tracked or committed.

Q12. How do you revert a commit in Git?

Ans: You can revert a commit using the "git revert" command followed by the commit hash or reference. It creates a new commit that undoes the changes made in the previous commit.

Q13. What is the difference between "git pull" and "git fetch"?

Ans: "git pull" fetches changes from a remote repository and merges them into the current branch, while "git fetch" only retrieves the changes without merging.

Q14. How do you undo the last commit in Git?

Ans: You can undo the last commit using the "git reset" command with the "--soft" or "--mixed" option, followed by the commit reference or HEAD~1.

Q15. What is a Git remote?

Ans: A Git remote is a reference to a remote repository. It allows you to fetch and push changes to and from the remote repository.

Q16. What is the purpose of Git stash?

Ans: Git stash is used to temporarily save changes that are not ready to be committed, allowing you to switch to a different branch without committing incomplete work.

Q17. How do you view the commit history in Git?

Ans: You can view the commit history using the "git log" command, which displays a list of commits, their messages, and other relevant details.

Q18. What is the difference between "git fetch" and "git pull"?

Ans: "git fetch" retrieves the latest changes from a remote repository without merging, while "git pull" retrieves the changes and merges them into the current branch.

Q19. How do you revert a file to a specific commit in Git?

Ans: You can revert a file to a specific commit using the "git checkout" command followed by the commit hash or reference and the file path.

Q20. How do you create a tag in Git?

Ans: You can create a tag in Git using the "git tag" command followed by the tag name and the commit hash or reference you want to tag.

Q21. What is the purpose of rebasing in Git?

Ans: Rebasing is used to incorporate changes from one branch into another, maintaining a linear commit history and avoiding unnecessary merge commits.

Q22. How do you delete a branch in Git?

Ans: You can delete a branch using the "git branch -d" command followed by the branch name. The branch must be merged into another branch before deletion.

Q23. How do you squash multiple commits into a single commit in Git?

Ans: You can squash multiple commits into a single commit using the "git rebase -i" command and specifying the commits you want to squash.

Q24. What is the purpose of Git hooks?

Ans: Git hooks are scripts that are executed automatically at specific points in the Git workflow, allowing you to customize and automate certain actions.

Q25. How do you contribute to an open-source project on GitHub?

Ans: You can contribute to an open-source project on GitHub by forking the repository, making changes in your forked repository, and creating a pull request to propose your changes to the original project.

Topics:Git and GitHub Interview Questions and Answers

Comments

Subscribe

Top Courses in Python

Top Courses in Python

We help you to choose the right Python career Path at myTectra. Here are the top courses in Python one can select. Learn More →

aathirai cut mango pickle

More...