Git Interview Questions & Answers
Git Interview Questions & Answers
com/@madhukiran_mindcircuit
Git Interview-Questions-Answers
1. What is Git?
Git is a distributed version control system used for tracking changes in source code during
software development.
Git allows developers to work locally with full version history, then push changes to a remote
repository like GitHub.
Git is distributed and allows offline work; SVN is centralized and requires internet
connectivity.
It’s a storage space where Git tracks and saves all changes made to project files.
A Git repo without a working directory, typically used as a central shared repository.
• This way, the bare repository acts like a GitHub or GitLab repository, but hosted in-
house.
• Since the repo is not meant for editing or working in, having a working directory is
unnecessary.
git config --global alias.co checkout makes git co work as git checkout.
git log
git branch -a
git fetch
• Downloads commits, files, and references from the remote repository into your local
repository, but does not merge them into your working directory.
• Ideal when you want to see what others have changed before integrating it into your
code.
git pull
• It fetches changes from the remote and then automatically merges them into your
current branch.
• Can cause merge conflicts if your local changes conflict with remote ones.
Edit the file manually, then git add and git commit.
33. How to check which branches have been merged into master?
Feature, Task, and Release branching (explain with real project use).
Temporarily stores changes not ready to commit. Useful when switching branches mid-work.
A request to merge changes from one branch to another, usually with a code review.
A merge where the target branch pointer is simply moved forward to the latest commit.
Annotated has metadata and is stored in Git history. Lightweight is just a pointer.
git revert
• Creates a new commit that undoes the changes made by a previous commit.
git reset
• Moves the HEAD and optionally updates the working directory and staging area.
• Can be destructive (especially with --hard), because it removes commits from history.
Common options:
52.What are the steps to push your code to a central repo (e.g., GitHub)?
git push
Example:
git push origin main – pushes your local main to the remote origin.
git pull
• It brings in changes from the remote repository into your current branch.
Example:
git pull origin main – fetches and merges changes from origin/main.
GitHub
• A popular platform for hosting Git repositories, especially used for open-source
projects.
• Owned by Microsoft and widely adopted by individual developers and the open-source
community.
• Strong features like GitHub Actions, Copilot, and seamless integration with VS Code.
Bitbucket
• Owned by Atlassian, and integrates deeply with Jira, Trello, and Confluence.
• Offers Bitbucket Pipelines for built-in CI/CD, great for managing private team projects.
55. You have code on your local machine and have pushed it to a remote repository. Now
you want to push the same code to a different (new) remote repository. How can you
change the remote URL?
git remote -v
Replace with the URL of the new Git repository (e.g., from GitHub or Bitbucket).