GIT interview questions and answers
Freshers / Beginner level questions & answers
Ques 1. What is Git?
Git is a distributed version control system that helps track changes in source code during software development.
Ques 2. Explain the difference between Git and GitHub.
Git is a version control system, while GitHub is a web-based platform for hosting and collaborating on Git repositories.
Ques 3. What is a commit in Git?
A commit is a snapshot of changes made to a Git repository. It creates a new revision in the version history.
Ques 4. What is a Git repository?
A Git repository is a storage location where a project's files and their revision history are stored.
Ques 5. Explain the purpose of 'git pull' command.
'git pull' is used to fetch and merge changes from a remote repository to the current branch.
Ques 6. What is the purpose of the '.gitignore' file?
The '.gitignore' file specifies files and directories that should be ignored by Git, preventing them from being tracked in the repository.
Ques 7. Explain the concept of Git branching.
Git branching allows developers to create independent lines of development, enabling them to work on features or bug fixes without affecting the main codebase until ready.
Ques 8. What is a Git stash, and how is it used?
A Git stash is a way to temporarily save changes that are not ready to be committed. It allows you to switch branches without committing or discarding changes.
Ques 9. How do you rename a Git branch?
You can use the 'git branch -m' command followed by the new branch name to rename a Git branch.
Ques 10. How can you view the commit history in Git?
You can use 'git log' to view the commit history, displaying information such as commit messages, authors, and timestamps.
Ques 11. Explain the purpose of the 'git clone' command.
'git clone' is used to create a copy of a remote repository on your local machine.
Ques 12. How do you amend the last Git commit message?
You can use 'git commit --amend' followed by the new commit message to amend the last commit.
Ques 13. How do you create a tag in Git?
You can use 'git tag' followed by the tag name to create a tag at the current commit.
Ques 14. Explain the purpose of the 'git log' command with the '--oneline' option.
'git log --oneline' provides a compact view of commit history, displaying each commit as a single line with a shortened commit hash and commit message.
Intermediate / 1 to 5 years experienced level questions & answers
Ques 15. How do you create a new branch in Git?
You can create a new branch using the 'git branch' command followed by the branch name.
Ques 16. Explain the 'git merge' command.
The 'git merge' command combines changes from different branches into the current branch.
Ques 17. What is a Git conflict, and how can it be resolved?
A Git conflict occurs when changes in one branch cannot be merged automatically. It can be resolved by manually editing the conflicting files.
Ques 18. How do you undo the last Git commit?
You can use 'git reset HEAD~1' to undo the last commit without discarding the changes.
Ques 19. How do you revert a commit that has already been pushed and shared with others?
You can use 'git revert' to create a new commit that undoes the changes introduced by the previous commit.
Ques 20. What is a Git submodule?
A Git submodule is a reference to a specific commit in another repository within the current repository. It allows for better organization and management of project dependencies.
Ques 21. Explain the purpose of the 'git cherry-pick' command.
'git cherry-pick' is used to apply specific commits from one branch to another.
Ques 22. What is the difference between 'git fetch' and 'git pull'?
'git fetch' retrieves changes from a remote repository without merging them, while 'git pull' fetches and merges changes in one command.
Ques 23. What is the purpose of 'git remote'?
'git remote' is used to manage remote repositories. It allows you to add, remove, or view the configured remote repositories.
Ques 24. What is the purpose of the '.gitattributes' file?
The '.gitattributes' file is used to define attributes and merge strategies for specific files in a Git repository.
Ques 25. Explain the difference between 'git push' and 'git pull' commands.
'git push' is used to upload local changes to a remote repository, while 'git pull' is used to fetch and merge changes from a remote repository.
Experienced / Expert level questions & answers
Ques 26. What is the difference between 'git rebase' and 'git merge'?
'git rebase' integrates changes from one branch to another by applying them individually, while 'git merge' combines changes as a single commit.
Ques 27. What is Git bisect, and how is it used?
Git bisect is a binary search tool that helps identify the commit where a bug was introduced. It is used by systematically narrowing down the commit range.
Ques 28. Explain the concept of Git rebase interactive.
Git rebase interactive allows you to selectively edit, reorder, or squash commits during the rebase process.
Ques 29. How do you squash multiple Git commits into a single commit?
You can use 'git rebase -i' and then combine or squash commits interactively during the rebase process.
Ques 30. What is Git subversion (git-svn)?
Git subversion is a Git extension that allows Git to interact with Subversion (SVN) repositories, enabling users to use Git locally while still collaborating with SVN.
Most helpful rated by users: