Git - Interview Question Set-1

 


Question-1: What happens when you run git fetch?

Answer: git fetch downloads new changes from a remote repository, but does not apply them to your local branch. 

It updates your remote-tracking branches so that they match the state of the corresponding branches on the remote repository.



Question-2: What is the difference between git merge and git rebase?

Answer: git merge combines changes from one branch into another branch, creating a new merge commit that has two parent commits. 

git rebase, on the other hand, rewrites the history of a branch by moving the branch to the tip of another branch and applying the changes in a linear fashion. 

This creates a cleaner, easier-to-understand commit history, but can lead to conflicts if multiple people are working on the same branch.



Question-3: You have made a commit that contains sensitive information, such as a password, and you want to remove it from the Git repository. What is the best way to do this?

Answer: The best way to remove a commit that contains sensitive information from the Git repository is to use the git filter-branch command. 


First, use the git log command to identify the commit that contains the sensitive information. 


Then, use the git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch path/to/file' --prune-empty --tag-name-filter cat -- --all command to remove the sensitive information from the commit and all subsequent commits. 

Finally, use the git push --force command to update the remote repository.



Question-4: How do you resolve conflicts in Git?

Answer: To resolve conflicts in Git, you first need to identify which files have conflicts by running git status. 

Then, open the conflicted files in a text editor and look for the sections marked with <<<<<<<, =======, and >>>>>>>. 

Edit the files to remove the conflict markers and make the necessary changes to resolve the conflicts. 

Once you have resolved all conflicts, stage the changes with git add and commit the changes with git commit.



Question-5: What is the difference between git push and git push --force?

Answer: git push sends your local changes to a remote repository and updates the remote branches to match your local branches. git push --force, however, overwrites the remote branches with your local branches, even if they have diverged. 


This can cause you to lose changes if you are not careful, so it should be used with caution.



Question-6: What is the difference between git reset and git revert?

Answer: git reset removes commits from the current branch, moving the branch pointer back to an earlier commit. 


This can be useful if you want to undo local changes that have not been pushed to a remote repository. git revert, on the other hand, creates a new commit that undoes the changes made by a previous commit. 


This is useful if you want to undo changes that have already been pushed to a remote repository and shared with others.



Question-7: You have made a mistake in a commit message and want to change it. What is the best way to do this?

Answer: The best way to change a commit message in Git is to use the git commit --amend command. 


First, use the git log command to identify the commit with the incorrect message. Then, use the git commit --amend -m "corrected message" command to change the commit message. 


Finally, use the git push --force command to update the remote repository.



Question-8: What is Git reflow?

Answer: Git reflow is a tool that simplifies Git workflows by automating the creation of pull requests and other common Git tasks. 


It provides a set of commands that allow developers to focus on writing code, rather than managing Git branches and pull requests.



Question-9: What is the difference between Git and GitHub?

Answer: Git is a distributed version control system that allows developers to track changes in source code over time. 


GitHub, on the other hand, is a web-based platform that provides hosting for Git repositories, as well as additional features such as issue tracking, code review, and collaboration tools.



Question-10: What is a Git hook?

Answer: A Git hook is a script that runs automatically before or after a Git command is executed. 


Hooks can be used to perform tasks such as checking for code quality, enforcing commit message formatting, and sending notifications. 


Git provides several pre-defined hooks, and developers can also create their own custom hooks.



 

No comments

Powered by Blogger.