Top 20 Git Interview Questions and Answers | git top 20 interview questions

                                    Git Interview Questions and Answers: -


Top 20 Git Interview Questions and Answers


  Top 20 Git Interview Questions and Answers



1.What is Git?

Answer: Git is a distributed version control system that allows multiple developers to collaborate on a project. It tracks changes to files, enables branching and merging, and provides a complete history of the project.

 

2.What is a repository in Git?

Answer: A repository in Git is a central location where the project and its version history are stored. It contains all the files, directories, and commits related to the project.

 

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

Answer: You can create a new branch in Git using the command git branch branch_name. To switch to the newly created branch, use git checkout branch_name.

 

4.What is the difference between Git and GitHub?

Answer: Git is a version control system, while GitHub is a web-based hosting service for Git repositories. GitHub provides additional collaboration features like pull requests, issue tracking, and project management tools.

 

5.How do you commit changes in Git?

Answer: To commit changes in Git, you need to use the command git commit -m "Commit message". This records the changes you have made to the repository.

 

6.What is a merge conflict in Git?

Answer: A merge conflict occurs when Git is unable to automatically merge changes from different branches. It happens when conflicting changes are made to the same lines of a file.

 

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

Answer: To resolve a merge conflict, you need to manually edit the conflicting files to choose the desired changes. After resolving the conflict, you can commit the changes to complete the merge.

 

 

 

8.How do you revert a commit in Git?

Answer: To revert a commit in Git, you can use the command git revert commit_id. This creates a new commit that undoes the changes made in the specified commit.

 

9.What is the purpose of the Git stash command?

Answer: The git stash command allows you to save your changes in a temporary area, allowing you to switch to a different branch without committing the changes. Later, you can apply the changes back to your working directory.

 

10.How do you update your local repository with the latest changes from the remote repository?

Answer: You can update your local repository with the latest changes by using the command git pull. This fetches the latest changes from the remote repository and merges them into your current branch.

 

11.How do you delete a branch in Git?

Answer: To delete a branch in Git, you can use the command git branch -d branch_name. This deletes the specified branch if it has been merged into other branches. To force delete a branch, use git branch -D branch_name.

 

12.What is the purpose of the .gitignore file?

Answer: The .gitignore file specifies patterns of files and directories that should be ignored by Git. It allows you to exclude certain files from being tracked or committed to the repository.

 

13.How do you create and apply a patch in Git?

Answer: To create a patch in Git, you can use the command git format-patch commit_range. To apply a patch, use git apply patch_file.

 

14.What is a remote repository in Git?

Answer: A remote repository in Git is a copy of the repository hosted on a different server. It allows multiple developers to collaborate by pushing and pulling changes to and from the remote repository.

 

15.How do you rename a branch in Git?

Answer: To rename a branch in Git, you can use the command git branch -m new_branch_name. This renames the current branch to the specified name.

 

16.What is the purpose of the git log command?

Answer: The git log command displays a detailed history of commits in the repository. It shows the author, date, commit message, and other relevant information.

 

17.How do you create and apply a Git patch?

Answer: To create a patch, you can use the command git format-patch commit_range. To apply a patch, use the command git apply patch_file.

 

18.How do you cherry-pick a commit in Git?

Answer: To cherry-pick a commit in Git, you can use the command git cherry-pick commit_id. This applies the changes made in the specified commit to your current branch.

 

19.What is Git rebase?

Answer: Git rebase is a command that allows you to modify the commit history of a branch. It can be used to combine, edit, or reorder commits to create a cleaner and more linear history.

 

20.How do you configure your Git username and email?

Answer: You can configure your Git username and email using the commands git config --global user.name "Your Name" and git config --global user.email "your@email.com". This information is associated with your commits.







Previous
Next Post »