Git is a free and open-source distributed version control system designed to handle small to large projects with speed and efficiency. It is the most widely used tool among developers around the world to build and contribute all types of projects. Git is simple to learn and has a tiny footprint with lightning-fast performance.
Table of Contents
Q1. What is Git?
Q2. What are branches in Git?
Q3. What is a repository?
Q4. What is a "bare repository”?
Q5. What is a "non-bare repository"?
Q6. What is a conflict in Git?
Q7. What is Stash in Git?
Q8. How can the user undo a commit that has been pushed already to a shared branch on a remote repository?
Q9. You have deleted a branch accidentally. Is there any way to recover it?
Q10. What is rebase in Git?
Q11. What is mean by "long-running" or "long-lived" branches in Git?
Q12. What are Submodules in Git?
Q13. How are you able to - with the assistance of Git - run a sanity check on code before it is committed to the repository?
Q14. Is it possible to change an old commit's message, although newer commits have already been created?
Q15. What is mean by "rewrite commit history"? Give some instances of when this can happen in Git.
Q16. Why is it demoralize to us "git push --force"? What are some of the potential downsides?
Q17. You committed on the "master" branch instead of "feature/login" accidentally. Describe the process of correcting this mistake.
Q18. You committed a file and only after some time noticed that it actually should have been "ignored." How can you solve this?
Q19. How can the user restore a previous version of your project?
Q20. Differentiate between "fetch" and "pull."
Q21. Git is a so-called "distributed" version control system. What's the difference to a "centralized" one?
Q22. What is commit?
Q23. Are Git and GitHub the same thing?
Q24. How to deal with large binary files in Git?
Q25. What do you mean by “git cherry-pick”?
Q26. When to use the "git cherry-pick" command?
Git cherry-pick command can sometimes end in duplicate commits, and thus, it must cautiously use it. The below-given situations are apt if forethought to use the Git cherry-pick command:
- When you accidentally make a commit in the wrong branch.
- When you want to make changes, other team members propose.
Q27. Why developers use Git Clone?
Q28. Why do you use SubGit?
Q29. Differentiate between HEAD, working tree, and index.
Q30. What are the benefits of using the Version Control System (VCS)?
- All members of the team can work on any file at any time without any restrictions.
- Allow us to estimate files, recognize differences, and merge the changes into a standard version.
- Keep track of application builds by determining which version is nowadays in development, QA, and production.
- Allows all team members to have complete knowledge of the project.
Q31. What is a "detached HEAD" in Git? Why is it considered a "dangerous" state?
Q32. For what purpose the Git Stash Drop and Git Stash Clear commands are used?
Q33. Explain Git Hooks.
Q34. Differentiate between Git stash apply and Git stash pop.
Q35. How can the user know if a branch has already been merged or not?
There are two commands to see these two things.
- Git branch –merged – This command provides a list of branches that are merged into this branch.
- Git branch –no-merged – This command provides a list of branches that haven’t been merged.
Q36. What’s the difference between reverting and resetting?
Q37. If you recover a removed branch, what work is returned?
Q38. 'git remote' is different from 'git clone.' How?
Q39. What command is used to fix a broken commit?
Q40. Differentiate between Git merge, and Git rebase?
To include new commits into your feature branch, you use Git merge.
- Creates an additional merge commit every time you need to include changes
- Pollutes your feature branch history
As another to merging, you can rebase the feature branch into master.
- Incorporates all the new commits within the master branch
Rewrites the project history by creating different commits for every commit in the original branch
Q41. Differentiate between fork, branch, and clone?
Q42. How do you find the list of files or sub-directories that has been changed in a specific commit?
The command to find the list of files that has been changed in a specific commit is:
git diff-tree –r {commit hash}
- -r flag allows the command to list separate files
- commit hash lists all the files that were changed or added in the commit.
Q43. What does the 'Git reset --mixed' and 'git merge --abort' commands do?
Q44. A bare repository is different from the standard way of initializing a Git repository. How?
Using a standard way:
- The user creates a working directory by executing the ‘git init’ command.
- A .git subfolder is created with all git-related change history.
Using a bare way:
- It doesn’t contain any working or checked-out copy of source files.
- Bare repositories contain git revision history in the root folder of your repository instead of the .git subfolder.
Q45. Which language is used in Git?
Q46. What are the advantages of using Git?
- Faster release cycles
- Easy team collaboration
- Widespread acceptance
- Maintains the integrity of source code
- Pull requests
Q47. Name some Git commands with their purpose.
- ‘Git config’ Configure the username and email address.
- ‘Git add’ Add one or more files to the staging area.
- ‘Git diff’ View the changes made to the file.
- ‘Git init’ Initialize an empty Git repository.
- ‘Git commit’ Commit changes to head but not to the remote repository.
Q48. How is the commit command executed?
Q49. Name some of the famous Git hosting repositories.
- GitHub
- GitLab
- BitBucket
- Beanstalk
- FogBugz
- Surround SCM
- Buddy
Q50. What is the method to revert a commit that has already been pushed and made public?
Following are the methods through which you can revert a commit:
- Delete or fix the bad file in a new commit and push it to the remote repository.
- Write a new commit to undo all the changes that were made in the bad commit.