3 RD Unit Devops
3 RD Unit Devops
and
more advanced aspects.
---
1. **What is Git?**
- **Answer:** Git is a distributed version control system that tracks changes in files, enabling multiple
developers to collaborate on projects by keeping history and managing changes efficiently.
- **Answer:** Git helps in version control, allowing developers to track changes, collaborate without
overwriting each other's work, revert to previous versions, and manage code efficiently.
- **Answer:** A VCS tracks changes to a file or set of files over time, allowing developers to revert to
previous versions, compare changes, and collaborate on a project. Git is a type of VCS.
- **Answer:** In Git, every developer has a local copy of the entire repository history, allowing them to
work independently and merge their changes later, unlike centralized VCS where everything relies on a
single server.
- **Answer:** A Git repository is a storage space where your project's files and their version history
are tracked. It can be local (on your computer) or remote (on platforms like GitHub).
- **Answer:** The two types of repositories are **local** (on a user's computer) and **remote**
(hosted on servers such as GitHub, GitLab, or Bitbucket).
7. **What is the role of GitHub with Git?**
- **Answer:** GitHub is a cloud-based hosting service that allows developers to store and manage
their Git repositories, collaborate with others, and use Git's version control features through a web-
based interface.
- **Answer:** Branching in Git allows developers to create separate versions of the project, so they
can work on different features, bug fixes, or experiments without affecting the main codebase.
- **Answer:** Tags in Git mark specific points in the repository's history, often used to signify
important events such as version releases. They are typically static unlike branches.
---
- **Answer:** The Git lifecycle consists of four main stages: **Untracked**, **Modified**,
**Staged**, and **Committed**. Files move through these stages during version control.
- **Answer:** An untracked file is a new file that has not yet been added to the version control system
and is not being tracked by Git.
- **Answer:** Staging means the file has been marked for inclusion in the next commit. It is stored in
the staging area but not yet committed to the repository.
4. **What is a commit in the Git lifecycle?**
- **Answer:** A commit captures the changes in the staged files and saves them as a new version in
the Git history, effectively recording a snapshot of the project.
- **Answer:** Staging is when changes are marked for inclusion in the next commit, but not yet saved,
while committing saves those changes to the repository's history.
- **Answer:** The working directory is the area where files are checked out from the repository and
where developers make changes. It's the current state of the project.
- **Answer:** A modified file has changes made to it that have not yet been staged or committed. It
resides in the working directory and is different from the last committed version.
- **Answer:** The staging area (or index) is an intermediate area where Git collects changes before
committing them to the repository.
9. **How do files move from the working directory to the staging area?**
- **Answer:** Files are moved from the working directory to the staging area using the `git add`
command.
10. **What is the difference between `git add` and `git commit`?**
- **Answer:** `git add` stages changes by adding files to the staging area, while `git commit` saves
those changes to the repository, creating a new commit in the history.
---
### **Common Git Commands**
- **Answer:** `git init` initializes a new Git repository in the current directory, setting up the necessary
files and folders for version control.
- **Answer:** `git clone` copies a remote Git repository to your local machine, allowing you to work on
the project locally.
- **Answer:** `git add` adds changes from the working directory to the staging area, preparing them
for the next commit.
- **Answer:** `git commit` saves changes from the staging area to the repository with a descriptive
message, creating a new commit in the project history.
- **Answer:** `git status` shows the current state of the working directory and staging area, indicating
which files are staged, unstaged, or untracked.
- **Answer:** The `git log` command displays the commit history, showing details such as commit
messages, authors, and timestamps.
- **Answer:** `git pull` fetches the latest changes from a remote repository and merges them into the
current branch, keeping the local repository up to date.
- **Answer:** `git branch` lists all branches in the repository and can create, delete, or rename
branches.
- **Answer:** `git merge` combines changes from one branch into another, often used to integrate
feature branches into the main branch.
---
- **Answer:** A typical Git workflow involves creating a new branch, making changes, committing
them, merging the branch into the main branch, and pushing the changes to a remote repository.
- **Answer:** Feature branching is a Git workflow where developers create separate branches for
each feature, allowing isolated development and easier collaboration.
- **Answer:** Branching allows developers to work on different features, bug fixes, or experiments
without affecting the main codebase, enabling parallel development.
- **Answer:** A pull request is a request to merge changes from one branch into another. It allows for
code review and discussion before the changes are accepted.
5. **What does a merge conflict mean in Git?**
- **Answer:** A merge conflict occurs when Git cannot automatically reconcile differences between
branches, requiring manual intervention to resolve the conflicting changes.
- **Answer:** Merge conflicts can be resolved by manually editing the conflicting files to choose the
correct changes, and then committing the resolved changes.
- **Answer:** Rebasing is the process of moving or combining commits from one branch onto another,
often used to clean up commit history or incorporate upstream changes.
- **Answer:** `git stash` temporarily saves changes that are not ready to be committed, allowing you
to switch branches or work on something else without losing progress.
- **Answer:** A fast-forward merge happens when the branch being merged has no new commits
after the branch point, allowing Git to move the branch pointer forward without creating a new commit.
---
- **Answer:** A remote repository is a version of your project hosted on a server, like GitHub, GitLab,
or Bitbucket, enabling collaboration and backup.
2. **How do you add a remote repository in Git?**
- **Answer:** The `git remote add <name> <url>` command links a remote repository to your local
repository, allowing you to push and pull changes.
3. **What
- **Answer:** `git fetch` downloads the latest changes from the remote repository without merging
them into your current branch, allowing you to review the changes first.
- **Answer:** `git pull` fetches and merges changes from a remote repository, while `git fetch` only
downloads the changes without merging.
- **Answer:** You use the `git push` command to upload your local commits to a remote repository,
making them available to others.
- **Answer:** `git remote -v` lists all the remote repositories linked to your local project, along with
their URLs.
- **Answer:** You can track a remote branch by using the `git checkout -b <branch>
<remote>/<branch>` command, which creates a local branch that tracks the remote branch.
- **Answer:** Cloning a repository copies all the files, branches, and history from the remote
repository to your local machine, creating a fully functional copy.
9. **What is the role of `git push origin <branch>`?**
- **Answer:** This command pushes the local branch to the remote repository named "origin,"
making the changes available remotely.
- **Answer:** The `git remote rm <name>` command removes the reference to a remote repository
from your local Git configuration.
---
- **Answer:** Version control in Git refers to tracking and managing changes to the project's files over
time, allowing for collaboration, rollback, and history management.
- **Answer:** Git tracks changes to files, stores version history, allows for branching and merging, and
facilitates collaboration by enabling multiple contributors to work on the same codebase.
- **Answer:** A commit is a snapshot of the project's state at a specific point in time. Each commit
records changes and is uniquely identified by a hash.
- **Answer:** Distributed version control allows every developer to have a complete history of the
project, enabling work offline, faster operations, and redundancy in case the central server is
unavailable.
- **Answer:** Git uses branches to allow multiple contributors to work independently on different
features or fixes, and then merges their work into the main project.
6. **What is the purpose of version tags in Git?**
- **Answer:** Tags mark specific points in the project history, typically used to signify version releases
or milestones, making it easy to identify stable or significant versions.
- **Answer:** When two developers make conflicting changes, Git detects these during merging and
flags them as conflicts. Developers must manually resolve these conflicts before the merge can proceed.
- **Answer:** Version rollback refers to reverting the project to a previous state or commit in the
history, undoing recent changes that might have introduced issues.
- **Answer:** Branching allows developers to work on separate copies of the codebase, enabling
version isolation, parallel development, and testing without impacting the main code.
- **Answer:** Semantic versioning is a convention for numbering releases (e.g., `v1.0.0`), where
version numbers indicate major, minor, and patch updates to the software, helping track changes
effectively.
---
These questions cover the core concepts related to Git, from basic version control to advanced
workflows with remote repositories, ensuring a deep understanding of Git's functionalities and uses.