Find Interview Questions for Top Companies
Ques:- How do Git internals work (objects, refs, trees, blobs)?
Right Answer:

Git internals consist of four main components:

1. **Objects**: Git stores data as objects, which include blobs, trees, commits, and tags. Each object is identified by a SHA-1 hash.

2. **Blobs**: These are binary large objects that store the content of files. Each file's content is stored as a blob.

3. **Trees**: Trees represent directories and contain references to blobs (files) and other trees (subdirectories). They maintain the structure of the repository.

4. **Refs**: Refs are pointers to commits. They include branches and tags, allowing Git to track different versions of the project.

Together, these components enable Git to efficiently manage version control and track changes in a repository.

Ques:- What is git cherry-pick and when would you use it?
Right Answer:

Git cherry-pick is a command that allows you to apply the changes from a specific commit in one branch to another branch. You would use it when you want to selectively apply certain commits without merging the entire branch, such as when you need a bug fix or feature from another branch without bringing in all other changes.

Ques:- What are tags in Git? How do you create and push them?
Right Answer:

Tags in Git are used to mark specific points in the repository's history, often to denote release versions. To create a tag, use the command `git tag <tag-name>`. To push tags to the remote repository, use `git push origin <tag-name>` or `git push –tags` to push all tags at once.

Ques:- How can you revert a pushed commit?
Right Answer:

To revert a pushed commit, use the command:

“`
git revert <commit-hash>
“`

This creates a new commit that undoes the changes made by the specified commit. After that, push the changes with:

“`
git push
“`

Ques:- What is a remote repository? How do you connect to one?
Right Answer:

A remote repository is a version of your project that is hosted on a server, allowing multiple users to collaborate. You connect to a remote repository using Git commands like `git clone` to copy it to your local machine, or `git remote add <name> <url>` to link your local repository to the remote one.

Ques:- What’s the difference between git pull and git fetch?
Right Answer:

`git fetch` downloads changes from the remote repository to your local repository but does not merge them into your working directory. `git pull` does both: it fetches the changes and then merges them into your current branch.

Ques:- How do you undo a commit that hasn’t been pushed yet?
Right Answer:

You can undo a commit that hasn’t been pushed yet by using the command `git reset HEAD~1`. This will remove the last commit while keeping your changes in the working directory.

Ques:- How do you resolve merge conflicts?
Right Answer:

To resolve merge conflicts in Git, follow these steps:

1. Identify the files with conflicts by running `git status`.
2. Open the conflicted files in a text editor. Look for conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`).
3. Manually edit the file to resolve the conflicts by choosing which changes to keep or combining them.
4. After resolving, save the file.
5. Stage the resolved files using `git add <filename>`.
6. Complete the merge by committing the changes with `git commit`.

Ques:- What is a detached HEAD in Git?
Right Answer:

A detached HEAD in Git occurs when the HEAD pointer is not pointing to a branch, but directly to a specific commit. This means you are not on a branch, and any new commits will not be associated with any branch until you create a new branch or switch back to an existing one.

Ques:- What is the difference between merge and rebase?
Right Answer:

Merge combines two branches by creating a new commit that includes changes from both, preserving the history of both branches. Rebase, on the other hand, moves or combines a sequence of commits to a new base commit, creating a linear history without a merge commit.

Ques:- What is .gitignore and why is it used?
Right Answer:

.gitignore is a file used in Git to specify which files or directories should be ignored by version control. It prevents certain files, like temporary files or sensitive information, from being tracked and included in commits.

Ques:- What is a commit? What does a commit contain?
Right Answer:

A commit in Git is a snapshot of changes made to the files in a repository. It contains the modified files, a unique identifier (hash), the author's information, a timestamp, and a commit message describing the changes.

Ques:- What is the difference between git add, git commit, and git push?
Right Answer:

– **git add**: Stages changes in your working directory for the next commit.
– **git commit**: Records the staged changes in the repository's history with a message.
– **git push**: Uploads your local commits to a remote repository.

Ques:- What is the difference between Git and GitHub?
Right Answer:

Git is a version control system that helps manage and track changes in code, while GitHub is a web-based platform that hosts Git repositories and provides collaboration features for developers.

Ques:- What is Git and why is it used
Right Answer:

Git is a distributed version control system used to track changes in source code during software development. It allows multiple developers to collaborate, manage code versions, and maintain a history of changes efficiently.



AmbitionBox Logo

What makes Takluu valuable for interview preparation?

1 Lakh+
Companies
6 Lakh+
Interview Questions
50K+
Job Profiles
20K+
Users