RATAN TATA MAHARASHTRA STATE SKILLS UNIVERSITY
School of Science Engineering and Technology Skills
Department of Engineering
Subject – DevOps and Automation Lab
Lab Assignment 3
To create a local Git repository and understand Git branching by performing basic Git
operations such as add, commit, status, history, and branch management.
Learning Objectives
After completing this lab, the student will be able to:
1. Understand the concept of Git branching.
2. Create and initialize a local Git repository.
3. Track file changes using Git commands.
4. Create and switch between branches.
5. Maintain commit history using Git.
6. Differentiate between staging and committing changes.
Theory
Git branching is a powerful feature that allows developers to diverge from the main line
of development and continue doing work without messing with that main line. It creates
an isolated environment for testing new features or fixing bugs. In Git, changes go
through a two-step process: they are first "staged" in an intermediate area, and then
"committed" to the repository's history, allowing for precise control over what gets
saved in each version.
Execution Procedure:
Steps
Step 1: Initialize the Repository
Create a new folder, open your terminal inside it, and type git init.
Step 2: Create, Add, and Commit a File
Create a text file (e.g., [Link]). Run git status to see it is
untracked. Run git add . to stage it. Run git commit -m
"Initial commit on master".
Step 3: Create and Switch to a New Branch
Type git branch feature-branch to create the branch. Then type
git checkout feature-branch to switch to it. (Alternatively, use
git checkout -b feature-branch to do both at once). Run git
branch to list branches and show the new one is active (highlighted
with an asterisk *).
Step 4: Make a Change on the New Branch
While on feature-branch, create a new file (e.g., feature-
[Link]). Run git add . and then git commit -m "Added
feature file".
Step 5: View the Commit History
Type git log --oneline (or just git log) to see the history of
your commits.
Questions :
1. What is a Master Branch?
Ans: The "master" branch (often referred to as the "main" branch in modern Git
environments) is the default, primary branch created when you initialize a new Git
repository. It typically represents the stable, production-ready version of your project's
codebase. All other feature branches eventually merge back into this main branch once
their code is tested and approved.
2. Difference Between git add and git commit.
• git add: This command updates the "staging area." It tells Git that you want to
include updates to a particular file in your next commit. It does not permanently
save the changes to the repository history; it just prepares them.
• git commit: This command takes everything currently in the staging area and
permanently saves a snapshot of it to the local repository's history, along with a
descriptive message.
3. Basic Git Commands & Syntax
Ans:
• git init: Initializes a new, empty Git repository in the current directory.
o Syntax: git init
• git status: Displays the state of the working directory and staging area, showing
which files are modified, staged, or untracked.
o Syntax: git status
• git add: Adds changes from the working directory to the staging area.
o Syntax: git add <file_name> or git add . (to add all changes).
• git commit: Records the staged changes as a permanent snapshot in the
repository's version history.
o Syntax: git commit -m "Your descriptive commit message"
• git branch: Lists all local branches. Can also be used to create or delete branches.
o Syntax: git branch (to list) or git branch <branch_name> (to create).
• git checkout: Switches the active working directory to a different branch.
o Syntax: git checkout <branch_name>
• git log: Displays the chronological history of commits for the current branch.
o Syntax: git log or git log --oneline (for a condensed view).