0% found this document useful (0 votes)
13 views9 pages

Lpic Devops 701 3

The document outlines the essential skills and commands for managing source code using Git, including repository structure, file operations, branching, tagging, and collaboration with remote repositories. It explains core concepts such as commits, trees, and blobs, as well as the process of merging and resolving conflicts. Additionally, it provides a comparison of centralized and distributed version control systems, along with practical command examples for various Git operations.

Uploaded by

milfrt13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views9 pages

Lpic Devops 701 3

The document outlines the essential skills and commands for managing source code using Git, including repository structure, file operations, branching, tagging, and collaboration with remote repositories. It explains core concepts such as commits, trees, and blobs, as well as the process of merging and resolving conflicts. Additionally, it provides a comparison of centralized and distributed version control systems, along with practical command examples for various Git operations.

Uploaded by

milfrt13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

701.3.

- Source Code Management


Weight 5
Description Candidates should be able to use Git to manage and share source
code. This includes creating and contributing to a repository as
well as the usage of tags, branches and remote repositories.
Furthermore, the candidate should be able to merge files and
resolve merging conflicts.

1.- Understand Git concepts and repository structure


Git is a distributed version control system (DVCS) that records changes to a file or
set of files over time so that you can recall specific versions later. Unlike centralized
systems, every developer has a full copy of the entire repository, including its
complete history. This allows for offline work and makes it highly resilient to central
server failures.

Repository:
Local Repository The copy of the project and its entire change history stored
on your local machine. It consists of:
• .git directory: The core of the Git repository. It
contains all the metadata for the repository, including
objects (commits, trees, blobs), references (branches,
tags), hooks, and configuration. This is where Git stores
everything that makes it a version control system.
• Working Directory: The actual files that you are
currently working on.
Remote Repository A version of the repository hosted on an internet or network
server, typically used for collaboration (e.g., GitHub, GitLab,
Bitbucket).

Three States of a Git File: Git manages files through three main states:
Core Concepts:
• Commit: A snapshot of your repository at a specific point in time. Each
commit has a unique SHA-1 hash, author, date, and a commit message. It
typically points to its parent commit(s).
• Tree: Represents the directory structure of a commit, containing pointers to
blobs and other trees.
• Blob: Represents the content of a file.
• HEAD: A symbolic reference to the current commit you are working on,
usually pointing to the tip of the current branch.

2.- Manage Files within a Git Repository.


Basic file operations are fundamental to Git usage.
COMMAND DESCRIPTION
git init Initializes a new Git repository in the current directory.
This creates the .git directory.
git add <file> Stages changes from the working directory to the staging
area.
git add . Stages all changes in the current directory and its
subdirectories.
git commit -m “mesg” Saves the staged changes to the local repository with a
descriptive message.
git status Shows the status of your working directory and staging
area (which files are modified, staged, untracked).
git diff Shows the differences between the working directory and
the staging area, or between commits.
git logs Displays the commit history of the repository.
git rm <file> Removes a file from the working directory and stages the
deletion.
git mv <old> <new> Renames a file and stages the rename.
.gitignore A text file that specifies intentionally untracked files that
Git should ignore (e.g., build artifacts, temporary files,
node_modules). Git will not show these files as
untracked in git status or include them in commits.
3.- Manage Branches and Tags
Branches and tags are core Git features for managing different lines of development
and marking important points in history.

Branches: A lightweight, movable pointer to a commit. They allow developers to


work on new features or bug fixes in isolation without affecting the main codebase.
COMMAND DESCRIPTION
main/master branch The default or primary branch, usually representing the
stable version of the code.
git branch Lists local branches.
git branch <branch- Creates a new branch.
name>
git checkout <branch- Switches to an existing branch (moves HEAD).
name>
git checkout -b <new- Creates a new branch and switches to it.
branch-name>
git branch -d <branch- Deletes a local branch (only if it's been merged).
name>
git branch -D <branch- Force-deletes a local branch (even if unmerged changes
name> exist).

Tags: Fixed, unchangeable pointers to specific commits, typically used to mark


release versions (e.g., v1.0.0). Unlike branches, tags don't move.
COMMAND DESCRIPTION
git tag Lists existing tags.
git tag <tag-name> Creates a lightweight tag on the current commit.
git tag -a <tag-name> Creates an annotated tag (recommended for releases,
-m "mesg" stores more metadata).
git show <tag-name> Shows information about a tag.
git push origin <tag- Pushes a specific tag to the remote repository.
name>
git push origin --tags Pushes all local tags to the remote repository.
4.- Work with Remote Repositories and Branches as well as Submodules
Collaboration in Git primarily happens through remote repositories.

Remote Repositories:
COMMAND DESCRIPTION
git remote Lists configured remote repositories.
git remote add <name> Adds a new remote repository (e.g., git remote add
<url> origin https://github.com/user/repo.git).
git clone <url> Clones a remote repository to your local machine, setting
up the origin remote automatically.
git fetch <remote- Downloads new commits and branches from a remote
name> repository but does not merge them into your local
branches.
git pull <remote-name> Fetches changes from a remote and automatically merges
<branch-name> them into the current local branch. (git pull is
essentially git fetch + git merge).
git push <remote- Uploads your local commits to the remote repository.
name> <branch-name>

Remote Branches: Represent the state of branches on the remote repository. They
are typically named remote-name/branch-name (e.g., origin/main).
COMMAND DESCRIPTION
git branch -r Lists remote branches.
git branch -a Lists all local and remote branches.

Submodules: Allows you to embed one Git repository inside another as a


subdirectory. This is useful when your project depends on another project that is
developed independently.
COMMAND DESCRIPTION
git submodule add Adds a new submodule.
<repository-url> <path>
git submodule update -- Initializes and updates submodules after cloning a
init --recursive repository containing them.
5.- Merge Files and Branches
Merging is the process of integrating changes from one branch into another.

COMMAND DESCRIPTION
git merge <branch-to- Integrates the specified branch into your current branch.
merge-in> • Fast-Forward Merge: If the target branch hasn't
diverged from the current branch, Git simply moves
the pointer forward.
• Three-Way Merge (Recursive Merge): If branches
have diverged, Git creates a new "merge commit"
that combines the changes from both branches,
preserving the history of both.
git rebase <branch-to- Another way to integrate changes. Instead of creating a
rebase-onto> merge commit, rebase moves or "replays" your commits
onto the tip of another branch. This creates a linear
history.
• Advantages: Cleaner, linear history.
• Disadvantages: Rewrites commit history, which
can be problematic if used on branches that have
already been shared with others (rebase is
dangerous for shared branches).
• Interactive Rebase (git rebase -i): Allows you
to squash, reorder, or edit commits during the
rebase process.

Resolving Merging Conflicts: Conflicts occur when Git cannot automatically


reconcile differences between two branches being merged (e.g., the same lines of
code were modified differently in both branches). Git inserts special markers in the
conflicting files (e.g., <<<<<<<, =======, >>>>>>>) to highlight the conflicting
sections. Resolution process:
1. Git will notify you of merge conflicts.
2. Use git status to see which files are conflicted.
3. Open the conflicted files, manually edit them to resolve the differences,
removing the conflict markers.
4. After resolving, git add <resolved-file> to stage the resolution.
5. git commit -m "Merge branch 'feature' into main": Commit the
merge (Git pre-populates a merge commit message).
6.- Awareness of SVN and CVS, including Concepts of Centralized and Distributed
SCM Solutions.
While Git is dominant, understanding its predecessors and the different SCM
paradigms provides context.
CVS DCVS
Concept There is a single, central Every developer has a complete
server that contains the entire copy of the entire repository,
project history. Developers including its full history.
"check out" files from this
central server and "check in"
their changes.
Examples • SVN (Subversion): • Git
Popular open-source • Mercurial
CVCS.
• CVS (Concurrent
Versions System):
Older open-source
CVCS, largely
superseded by SVN.
Characteristics • Single point of failure (if • No single point of failure.
the central server goes • Allows for offline work.
down, no one can • Fast operations (most
collaborate or access operations are local).
history). • Flexible workflows (topic
• Requires network branching, pull requests).
connectivity for most • Robust branching and
operations. merging capabilities.
• Branching and merging
are often more complex
and less efficient than in
Git.
1.- What is true about a commit in git?
a) A commit can be changed if it has not been uploaded to a remote repository.
b) A commit contains information about all branches of a given repository.
c) A commit requires all remote repositories to be synchronized before
completing.
d) A commit has to be acknowledged by all remote repositories before it is
completed.
e) A commit can contain changes to the content of submodules of a repository.

2.- What is the difference between the commands git diff and git diff --cached?
(Choose TWO correct answers)
a) git diff --cached shows changes of all commits that were not pushed to origin
yet.
b) git diff shows changes that were not added to the next commit.
c) git diff and git diff --cached always lead to the same result if a repository does
not have at least one remote repository.
d) git diff --cached shows changes that will be included in the next commit.
e) git diff --cached shows changes included in the last successful commit of the
current branch.

3.- After creating a new file within a directory which to a Git repository, which
commands have to be used in order to make Git manage the new file and upload it
to the already existing remote origin?(Choose THREE correct answers)
a) git init
b) git push
c) git commit
d) git add
e) git remote

4.- Which git command restores changes that were saved using git stash save?
a) git stash merge
b) git stash revert
c) git stash pop
d) git stash restore
e) git stash commit
5.- The following output is generated by git branch:
development
mater
production
*staging
How can all changes from the development branch be integrated into the staging
branch?
a) git stash development
b) git merge development
c) git branch --merge development
d) git merge delopment..staging
e) git cp --merge development

6.- FWhich git sub command copies a local commit to a remote repository?
(Specify ONLY the sub command without any path or parameters.)
git push

7.- Which of the following git commands is used to manage files in a repository?
(Choose two correct answers.)
a) git rm
b) git cp
c) git mv
d) git move
e) git copy

8.- The file index.php, which is being maintained in a git repository, was
changed locally and contains an error. If the error has not been committed
to the repository yet, which of the following git commands reverts the
local copy of index.php to the latest committed version in the current
branch?
a) git lastver "" index.php
b) git revert "" index.php
c) git checkout "" index.php
d) git clean "" index.php
e) git repair "" index.php
9.- Which of the following information is contained in the output of git
status? (Choose three correct answers.)
a) Changed files that will not be part of the next commit.
b) Locked files which cannot be edited until the lock is released.
c) Changed files that will be part of the next commit.
d) Unchanged files which have not been edited locally.
e) Untracked files which are not subject to version control.

10.- What happens when a merge conflict occurs in git? (Choose two correct
answers.)
a) The conflicting files remain unchanged in the local repository.
b) Conflict markers are added to the files.
c) A new branch containing the remote changes is created.
d) The affected files are flagged as conflicting.
e) The newest version is placed in the local repository.

You might also like