1.
What is Git ?
Git is a distributed version control system (VCS) that helps developers track changes to files, coordinate with other developers, and manage their source code. It's widely used in software development and allows multiple developers to collaborate on the same project while keeping a history of changes, making it easier to manage code versions, share updates, and resolve conflicts.
Git is a powerful and flexible tool for managing code versions, enabling smooth collaboration between developers, and providing control over the history and changes in a project. Its distributed nature makes it particularly suited for teams and large projects, and it integrates well with platforms like GitHub, GitLab, and Bitbucket for online collaboration and code sharing.
2.
What is the difference between Git and SVN (Subversion) ?
Git :
is more powerful, flexible, and suited to modern development workflows, especially when working in distributed teams. Its speed, branching and merging capabilities, and offline work make it the preferred choice for many developers today.
SVN :
can be a good choice for smaller teams or projects where a centralized repository is preferred, or where the team has experience with older centralized systems. It offers simpler workflows but lacks the flexibility and power of Git for larger, more complex projects.
3.
What is a repository in Git?
In Git, a repository (or repo) is a directory or storage space where your project's files and the history of all changes made to those files are stored. It is a core concept in Git and serves as the workspace where all your code, version history, commits, branches, and configurations reside.
a repository is essentially the heart of version control. It tracks your project’s files and their history, allows you to manage different versions of the code with branches, and enables collaboration by syncing with remote repositories. Whether it's a personal project or a team-based development effort, the Git repository is central to managing and coordinating changes to the codebase.
4.
What is a commit in Git?
A commit in Git is essentially a snapshot of your project at a particular point in time. It represents a set of changes that have been recorded in the repository. Each commit captures the state of the repository, including the changes to files and directories, and is identified by a unique hash (a long string generated using a cryptographic function). Commits are fundamental in tracking the history of a project and help developers collaborate by providing a record of all changes.
In Git, a commit is a snapshot of your changes in the repository, stored with metadata such as the commit message, author, timestamp, and unique identifier (hash). Commits form the history of a project, enabling developers to track changes, collaborate, and revert to previous versions.
5.
What is a branch in Git?
A branch in Git is a separate line of development that allows you to work on different features, fixes, or experiments in isolation from the main codebase. It is one of the most powerful features of Git and enables multiple developers to work on different parts of a project simultaneously without interfering with each other’s work.
In Git, a branch is a way to create an independent line of development, enabling developers to work on features, fixes, or experiments in isolation. Branching is crucial for collaborative development, version control, and maintaining a clean project history. Whether you’re working alone or in a team, using branches allows you to manage and organize your codebase efficiently.
6.
What is the difference between a fork and a clone in Git?
Fork :
A fork is essentially a copy of a repository that is created on a remote server (like GitHub, GitLab, Bitbucket, etc.) under your own account. It’s typically used in open-source development or collaborative projects, where you want to contribute to a project without directly modifying the original repository.
Clone :
A clone is a copy of a repository, but it is created on your local machine. When you clone a repository, you get the entire repository history, all files, branches, and commit history. Cloning is often done to get a local working copy of a repository to make changes.
7.
What is a pull request in Git?
A pull request (often abbreviated as PR) is a feature used in Git-based collaboration platforms like GitHub, GitLab, and Bitbucket that allows you to propose changes to a repository. It’s a way for contributors to submit their changes (usually from a feature branch) to be reviewed and, if approved, merged into another branch (typically the main or master branch) of the repository.
In simpler terms, a pull request is like a request to "pull" your changes from one branch (often a forked or feature branch) into another branch (usually the main branch) of the repository.A pull request in Git is a method of proposing changes to a repository.
8.
What is the difference between git pull and git fetch?
git fetch:
Updates your local references to remote branches, but doesn’t affect your working directory or current branch. It’s a safe way to check for changes on the remote without making any changes locally.It fetches the changes from the remote repository but doesn’t automatically integrate them into your working directory or local branch.
git pull:
Fetches the latest changes from the remote and automatically merges those changes into your current branch, potentially affecting your working directory. It’s a faster way to sync your local branch with the remote branch.It first fetches the latest changes from the remote repository, and then automatically merges those changes into your current working branch.
9.
What is the staging area in Git?
The staging area (also known as the index) in Git is a temporary area where changes to your files are placed before they are committed to the repository. It acts as a buffer between the working directory and the local repository. The staging area allows you to prepare and organize your changes before committing them to the Git history.
The staging area in Git acts as a buffer between your working directory and the Git repository.
You use the staging area to prepare and organize changes before committing them to the repository.
10.
What is the git status command used for?
The git status command in Git is used to show the current state of your working directory and staging area. It provides valuable information about which changes have been made, which files are staged for commit, and which files are untracked or modified.
The git status command is a fundamental tool in Git that helps you track the state of your working directory and staging area. It provides critical information about what has been modified, staged, and committed, helping you understand what’s going on with your project and guiding you through your workflow. It’s often the first command run when you're unsure about the state of your repository or before making important actions like commits or merges.
11.
What is git merge and how does it work?
git merge is a command used in Git to integrate changes from one branch into another. Specifically, it allows you to combine the work from two branches into a single unified branch. This is commonly done when you want to bring changes from a feature branch or another branch into your current working branch (often the main or master branch).
The git merge command performs a merge operation that takes the changes from the specified branch and applies them to the current branch you're working on.
git merge is a critical part of collaborative Git workflows, helping you combine work from multiple contributors into a single, unified codebase.
12.
What is a conflict in Git, and how can you resolve it?
A conflict in Git occurs when changes in two different branches cannot be automatically reconciled. This typically happens when:
- Two branches modify the same line(s) of a file, or
- One branch deletes a file while another branch modifies the same file.
When this happens, Git cannot decide which version of the changes to keep, so it marks the file as conflicted and requires the user to manually resolve the differences.Good Practices include frequent communication with your team, using merge tools, and keeping branches up to date to minimize conflicts.
13.
What is the purpose of .gitignore?
The .gitignore file in Git is used to tell Git which files or directories to ignore in a repository. This means that the files and directories listed in .gitignore will not be tracked by Git, and they won't be staged, committed, or pushed to remote repositories.
The purpose of .gitignore is to prevent unnecessary files, such as temporary files, build artifacts, configuration files, or sensitive information, from being included in the version control system. This helps keep the repository clean, reduces clutter, and avoids the accidental inclusion of files that should not be shared or versioned.
14.
What is a remote repository in Git?
A remote repository in Git is a version-controlled repository that is hosted on a server or a cloud-based service (like GitHub, GitLab, or Bitbucket). It allows multiple users to collaborate on the same project by pushing and pulling changes from a shared repository. Unlike a local repository, which resides on your local machine, a remote repository is typically used to store and share your project's history with other contributors.
A remote repository is a version-controlled repository hosted on a server or a cloud service. It allows multiple users to collaborate by sharing and syncing code.
You can interact with remote repositories by pushing and pulling changes, as well as fetching or viewing information about them.
15.
What is git rebase?
git rebase is a powerful Git command that allows you to integrate changes from one branch into another by replaying the commits from one branch onto another. It is often used to maintain a cleaner project history by avoiding unnecessary merge commits.
When you use git rebase, Git takes the commits from the source branch (the branch you're rebasing) and applies them on top of the target branch (the branch you want to rebase onto), one by one. This results in a linear history, as opposed to a branching history that would occur with a merge.
git rebase is a powerful tool for integrating changes from one branch into another while maintaining a cleaner, linear commit history.
16.
What is git log used for?
The git log command in Git is used to display the commit history of the current repository or a specified branch. It provides a detailed log of all the commits made in a repository, showing information about each commit, such as the commit hash, author, date, and commit message.
git log is used to view the commit history of a Git repository.
It provides detailed information about each commit, such as the commit hash, author, date, and commit message.
You can customize its output with various options (e.g., limiting the number of commits, viewing commits in a specific file, or showing changes made in each commit).
17.
What is the difference between git reset and git revert?
git reset :
git reset is used to move the current HEAD (the pointer to the current commit) to a specific commit, effectively changing the state of your repository.It removes commits (from the branch history) or changes the index (staging area) based on the reset mode used.
git revert :
git revert is used to create a new commit that undoes the changes made by a previous commit. Instead of modifying the commit history like git reset, it adds a new commit that undoes the effect of a commit.It does not alter the commit history but creates a new commit that reverses the changes introduced by the commit you want to revert.
18.
What is git clone used for?
The git clone command is used to create a copy of a remote Git repository on your local machine. When you clone a repository, Git copies the entire repository, including its commit history, branches, and files, so you can work on it locally.
git clone is the command you use to duplicate an entire Git repository from a remote source to your local machine, enabling you to work on the project independently while still being able to interact with the remote version.
19.
What is the purpose of git diff?
The git diff command is used to show the differences between various states of your repository. It compares changes in your working directory or staging area with the repository's history. In essence, it helps you see what changes have been made, whether it's between commits, between your working directory and the staging area, or between the staging area and the last commit.
git diff is a diffing tool that helps you understand the changes you’ve made, either in the working directory or staging area, by comparing them to the repository’s history. It’s a crucial command for reviewing, tracking, and understanding changes before committing or pushing them.
20.
What is git tag?
The git tag command is used to create tags in your Git repository. A tag is a reference to a specific commit in your Git history, typically used to mark significant points in the project’s development. Tags are often used to mark versions or releases, like v1.0.0, v2.0.0, etc.
git tag is a useful tool for marking specific points in your repository’s history. It is commonly used for marking version releases, ensuring that you can easily reference, share, and revert to those points as needed. Tags can be lightweight or annotated, with annotated tags generally recommended for tracking releases due to the additional metadata they include.
21.
How do you delete a branch in Git?
- To delete a local branch, you can use the git branch -d or git branch -D command:
git branch -d <branch_name>: This safely deletes a local branch, but only if it has been fully merged into the current branch or another specified branch. It prevents you from accidentally losing unmerged changes.
- To delete a branch from a remote repository, you use the git push command with the --delete flag:
git push --delete <remote> <branch_name>: This deletes the specified branch from the remote repository.
22.
What is git cherry-pick?
git cherry-pick is a command used to apply a commit from one branch to another. It allows you to select specific commits from a different branch and "pick" them to be applied to your current branch, instead of merging or rebasing entire branches. This is especially useful when you want to apply a single commit or a range of commits without including the rest of the history from the source branch.
git cherry-pick is a powerful tool for selectively applying commits from one branch to another. It's helpful when you need to bring in specific changes without the complexity of merging entire branches. However, it should be used carefully, as it may result in conflicts that need to be manually resolved.
23.
What is the git blame command used for?
The git blame command is used to show who made changes to each line of a file and when the changes were made. It helps you trace the author and commit associated with each line in a file, making it easier to track the history of changes, identify the person responsible for specific modifications, and understand the context behind a particular line of code.
git blame is a valuable command for tracing the history of a file, providing detailed information about the authorship of each line of code. It is commonly used for debugging, understanding code changes, and improving collaboration by identifying the person responsible for specific modifications.
24.
What are the advantages of using MongoDB over traditional relational databases?
MongoDB :
is schema-less, meaning that each document (record) in a collection can have a different structure. This flexibility allows you to easily store and manipulate different kinds of data, which can be particularly useful in dynamic or evolving applications.MongoDB is optimized for storing and processing large volumes of unstructured or semi-structured data. This makes it a good fit for applications dealing with high volumes of log data, social media feeds, or sensor data.
Relational databases :
on the other hand, require a predefined schema (table structure) that all records must adhere to. This can be restrictive when your data is varied or evolving.
In contrast, relational databases can become slower and more complex to manage when dealing with large, unstructured data sets, especially when attempting to scale.
25.
Explain the concept of Write Concern in MongoDB.
Write Concern defines the level of acknowledgment requested from MongoDB for write operations to a document. It ensures that write operations are acknowledged by the database. The possible write concern levels are:
- w: 1: Acknowledgment from the primary node only.
- w: "majority": Acknowledgment from a majority of nodes in the replica set.
- w: 0: No acknowledgment from the database (write is not confirmed).
- j: true: Ensures the write operation is written to the journal before it’s acknowledged.
- wtimeout: Defines a timeout period for waiting for acknowledgment.