GIT Interview Questions


What is Git?

Git is a distributed version control system that allows you to track changes made to your code over time. It is a tool that helps developers collaborate and manage changes to their codebase.

What is the difference between Git and GitHub?

Git is a version control system, whereas GitHub is a web-based hosting service for Git repositories. In other words, Git is the tool you use to manage your code changes, and GitHub is the platform you use to store and share those changes with others.

Q: What is the difference between a fetch and a pull in Git?

A fetch in Git downloads changes from a remote repository to your local repository, but does not apply those changes to your code. A pull in Git, on the other hand, downloads changes from a remote repository and applies them to your code.

How do you create a new Git repository?

To create a new Git repository, navigate to the directory you want to initialize the repository in and run the command “git init”.

How do you add files to a Git repository?

To add files to a Git repository, use the command “git add <filename>” for individual files or “git add .” to add all files in the current directory.

How do you commit changes to a Git repository?

To commit changes to a Git repository, use the command “git commit -m “Commit message” “.

How do you create a new branch in Git?

To create a new branch in Git, use the command “git branch <branch name>”.

How do you switch to a different branch in Git?

To switch to a different branch in Git, use the command “git checkout <branch name>”.

How do you merge two branches in Git?

To merge two branches in Git, first checkout the branch you want to merge into, then use the command “git merge <branch name>”.

How do you resolve merge conflicts in Git?

To resolve merge conflicts in Git, first identify the conflicts using the command “git status”. Then open the affected files, resolve the conflicts, and save the changes. Finally, stage and commit the changes.

How do you push changes to a remote Git repository?

To push changes to a remote Git repository, use the command “git push <remote> <branch name>”.

How do you pull changes from a remote Git repository?

To pull changes from a remote Git repository, use the command “git pull <remote> <branch name>”.

How do you revert changes in Git?

To revert changes in Git, use the command “git revert <commit hash>”. This will create a new commit that undoes the changes made in the specified commit.

What is a repository in Git?

A Git repository is a directory on your local machine that contains your project files and all the history of changes made to those files. It is a place where Git stores all the snapshots of your code and its history.

What is a commit in Git?

A commit in Git is a snapshot of your code at a specific point in time. When you make changes to your code, you create a new commit that represents those changes. Each commit has a unique identifier and contains a record of the changes you made.

What is a branch in Git?

A branch in Git is a separate line of development that allows you to work on new features or make changes to your code without affecting the main codebase. It is like a parallel universe where you can make changes to your code independently of what others are doing.

What is a merge in Git?

A merge in Git is the process of combining changes from one branch into another. When you merge two branches, Git creates a new commit that represents the combination of those changes.

What is a pull request in Git?

A pull request in Git is a way to propose changes to a repository hosted on GitHub. It allows you to notify other developers about the changes you’ve made and request their review before merging your changes into the main codebase.

What is a conflict in Git?

A: A conflict in Git occurs when two or more developers make changes to the same file or lines of code, and those changes cannot be automatically merged by Git. Resolving conflicts requires manual intervention by the developers to decide which changes to keep and which to discard.

What is a tag in Git?

A: A tag in Git is a reference to a specific commit that is used to mark a specific point in the history of your codebase. It is often used to indicate the release of a new version of your software.

Explain Git rebase?

A: Git rebase is a command that allows you to modify the history of your Git repository. It is used to rewrite the commit history by reapplying commits from one branch to another, and can be used to clean up your commit history or to integrate changes from one branch into another.

What is Git stash?

A: Git stash is a command that allows you to temporarily save changes that are not ready to be committed. It allows you to switch branches or work on a different task without committing your changes, and then later restore those changes when you’re ready to continue working on them.

What is Git bisect?

A: Git bisect is a command that allows you to find the commit that introduced a bug in your code. It works by performing a binary search through your commit history to identify the commit where the bug was introduced.