GIT
GIT
Basics of Git:
1. What is Git?
o Answer: Use the command git init to initialize a new Git repository.
• Answer: Use the command git reset HEAD^ to undo the last commit. This
command keeps changes in your working directory.
Branching and Merging:
11. What is a branch in Git?
13. Explain the difference between git merge and git rebase.
o Answer: git merge combines changes from different branches, creating
a new commit. git rebase moves or combines a sequence of commits
to a new base commit.
17. Explain the difference between git push and git pull.
o Answer: git push sends local changes to a remote repository. git
pull retrieves changes from a remote repository and merges them into
the local branch.
Git Workflow:
21. Explain the Gitflow workflow.
o Answer: Use the interactive rebase with the command git rebase -i
HEAD~n, where n is the number of commits. Squash or fixup commits
during the rebase.
o Answer: Git hooks are scripts that run automatically at key points in
the Git workflow. They allow customizing and automating actions such
as pre-commit checks or post-receive deployments.
Advanced Git:
26. What is git bisect used for?
o Answer: git bisect is used to find the commit that introduced a bug. It
performs a binary search through the commit history to locate the
faulty commit.
27. How do you change the last commit message in Git?
28. Explain the difference between git cherry-pick and git rebase.
o Answer: git cherry-pick applies specific commits to the current
branch. git rebase moves or combines a sequence of commits.
30. How do you remove a file from Git without deleting it locally?
Git Commands:
o Answer: Use the command git log to show the commit history.
Options like --oneline and --graph provide more concise or graphical
views.
33. What is the purpose of git cherry-pick?
o Answer: git cherry-pick is used to apply specific commits from one
branch to another.
34. How do you create a new branch and switch to it in one command?
Git Configurations:
41. How do you set up Git globally on your machine?
44. What is the purpose of Git hooks, and where are they stored?
o Answer: Git hooks are scripts that run at specific points in the Git
workflow. They are stored in the .git/hooks directory of a Git
repository.
o Answer: Use the command git remote -v to list all configured remote
repositories along with their URLs.
Git Security:
46. Explain the concept of Git SSH keys.
o Answer: Git SSH keys are used for secure authentication between a Git
client and a remote repository. They ensure secure communication
without the need for entering a password.
49. How do you change the Git remote URL from HTTPS to SSH?
50. What is the purpose of Git stash, and how do you use it?
o Answer: Git stash is used to temporarily save changes that are not
ready to be committed. Use git stash to save changes and git stash
apply to retrieve them later.
Git Internals:
51. Explain the Git object model.
o Answer: The Git object model consists of four main object types: blobs
(file content), trees (directory structure), commits (snapshot and
metadata), and tags (references to commits).
52. What is the difference between a shallow clone and a deep clone in Git?
o Answer: The Git index (staging area) is a file that contains information
about files to be included in the next commit. It acts as a bridge
between the working directory and the repository.