Desktop View Only

Desktop Device Required

This Laboratory Manual contains standard A4 page layouts, code terminals, and multi-column tables designed exclusively for desktop and laptop displays.

💡 Tip: Please open this manual on a PC or laptop, or enable "Desktop site" mode in your mobile browser.
Git Laboratory Illustration
P A COLLEGE
OF ENGINEERING
AFFILIATED TO VTU | RECOGNIZED BY GOVT. OF KARNATAKA
APPROVED BY AICTE | GRADED A BY NAAC | ACCREDITED BY NBA
PROJECT MANAGEMENT WITH GIT
LABORATORY MANUAL

A practical guide to Git-based project management covering basic commands, branching, collaboration, remote repositories, tags, advanced operations, and Git history.

SEMESTER
III SEMESTER – B.E.
COURSE CODE
BCS358C
SCHEME
VTU 2022 SCHEME (CBCS)
Decoration

Department Vision & Mission

THE VISION

To be a center of excellence in providing quality education of global standards and be a pioneer in spreading the knowledge and innovative ideas of Computer Science and Engineering for catering the industrial demands and societal needs.

THE MISSION
  • M1: To develop competent innovative professionals having effective communication skills with proficiency in real world problem solving with leadership traits.
  • M2: To impart quality and value based education to reach the expectations of all the stakeholders through an ever evolving, effective and creative teaching-learning process.
  • M3: To undertake salient research works for the establishment of center of excellence in the field of Computer Science and Engineering and multi-disciplinary domains.

Program Educational Objectives (PEOs) & Program Specific Outcomes (PSOs)

Program Educational Objectives (PEOs)
  • PEO 1: Graduates of the program will analyze, design and solve problems related to Computer Science and Engineering and possess adaptability to changes in technology by self-learning.
  • PEO 2: Graduates are provided with an educational foundation that prepares them for leadership roles in their diverse career paths and to pursue higher education.
  • PEO 3: Graduates of the program are capable to deliver the software product for various real life problems within the scheduled time.
  • PEO 4: Graduates must develop professional and communication skills for their successful professional career.
Program Specific Outcomes (PSOs)
  • PSO 1: Analyze, design and develop advanced software and hardware solutions to address complex real-world problems with innovative technologies and methodologies.
  • PSO 2: Develop intelligent systems with professionalism and ethical responsibility, effectively communicating and collaborating in multidisciplinary teams adhering to best industry practices.

Program Outcomes (POs)

PO Graduate Attribute & Statement PO Graduate Attribute & Statement
PO1 Engineering knowledge: Apply knowledge of mathematics, natural science, computing, engineering fundamentals to complex engineering problems. PO7 Ethics: Apply ethical principles and commit to professional ethics, human values, diversity and inclusion; adhere to national & international laws.
PO2 Problem analysis: Identify, formulate, review research literature and analyze complex engineering problems reaching substantiated conclusions. PO8 Individual & Team work: Function effectively as an individual, and as a member or leader in diverse/multi-disciplinary teams.
PO3 Design/development of solutions: Design creative solutions for complex problems and system components meeting identified needs. PO9 Communication: Communicate effectively and inclusively with engineering community & society, write effective reports & design documentation.
PO4 Conduct investigations: Conduct investigations of complex engineering problems using research-based knowledge and experiments. PO10 Project Management & Finance: Apply engineering management principles and economic decision-making to one's own work & team projects.
PO5 Engineering Tool Usage: Create, select and apply appropriate techniques, resources and modern engineering & IT tools (prediction/modelling). PO11 Life-Long Learning: Recognize the need for independent and life-long learning, adaptability to new and emerging technologies & critical thinking.
PO6 The Engineer & The World: Analyze & evaluate societal and environmental aspects, sustainability, economy, health, safety, and legal framework. - -
Decoration

Course Information & Examination Scheme

Course Title Course Code Teaching Hours (L:T:P:S) CIE Marks SEE Marks Exam Duration
Project Management with Git BCS358C 0 : 0 : 2 : 0 50 Marks 50 Marks 02 Hours (Practical)
Course Objectives
  • To be familiar with basic commands of Git.
  • To create and manage branches.
  • To understand how to collaborate and work with Remote Repositories.
  • To be familiar with version controlling commands.
Course Outcomes (COs)
  • Use the basic commands related to git repository.
  • Create and manage the branches.
  • Apply commands related to Collaboration and Remote Repositories.
  • Use commands related to Git Tags, Releases, and advanced operations.
  • Analyse and change the git history.

Assessment Details (CIE & SEE)

The weightage of Continuous Internal Evaluation (CIE) is 50% (50 Marks) and Semester End Exam (SEE) is 50% (50 Marks). Minimum passing mark for CIE is 40% (20/50 marks) and for SEE is 35% (18/50 marks). Aggregate minimum passing mark is 40% (40/100 marks).

Continuous Internal Evaluation (CIE - 50M)

• Record / Journal (60%): Scaled down to 30 Marks.
• Department Lab Test (40%): Conducted for 100M after syllabus completion; scaled down to 20 Marks (Write-up & Conduction 60%, Viva-Voce 40%).

Semester End Exam (SEE - 50M)

• Evaluated for 100 Marks, scaled down to 50 Marks (Duration: 02 Hours).
• Breakup: Write-up (20%), Conduction & Result (60%), Viva-Voce (20%).

Decoration

VTU Prescribed Laboratory Experiments

Sl. No. Module / Category Experiment Problem Statement / Aim
1 Setting Up and Basic Commands Initialize a new Git repository in a directory. Create a new file and add it to the staging area and commit the changes with an appropriate commit message.
2 Creating and Managing Branches Create a new branch named "feature-branch." Switch to the "master" branch. Merge the "feature-branch" into "master."
3 Creating and Managing Branches Write the commands to stash your changes, switch branches, and then apply the stashed changes.
4 Collaboration and Remote Repositories Clone a remote Git repository to your local machine.
5 Collaboration and Remote Repositories Fetch the latest changes from a remote repository and rebase your local branch onto the updated remote branch.
6 Collaboration and Remote Repositories Write the command to merge "feature-branch" into "master" while providing a custom commit message for the merge.
7 Git Tags and Releases Write the command to create a lightweight Git tag named "v1.0" for a commit in your local repository.
8 Advanced Git Operations Write the command to cherry-pick a range of commits from "source-branch" to the current branch.
9 Analysing and Changing Git History Given a commit ID, how would you use Git to view the details of that specific commit, including the author, date, and commit message?
10 Analysing and Changing Git History Write the command to list all commits made by the author "JohnDoe" between "2023-01-01" and "2023-12-31."
11 Analysing and Changing Git History Write the command to display the last five commits in the repository's history.
12 Analysing and Changing Git History Write the command to undo the changes introduced by the commit with the ID "abc123".
SEE Examination Guidelines: Students pick one experiment from the questions lot prepared jointly by examiners. Change of experiment is allowed only once with 15% procedure marks made zero.
Decoration

Introduction to Git

Git is a distributed version control system (VCS) that is widely used for tracking changes in source code during software development. It was created by Linus Torvalds in 2005 and has since become the de facto standard for version control in the software development industry. Git allows multiple developers to collaborate on a project by providing a history of changes, facilitating the tracking of who made what changes and when.

Key Concepts and Features of Git

1. Repository (Repo)
A directory or storage location where your project's files and version history are stored. There can be a local repository on your computer and remote repositories on servers.
2. Commits
In Git, a commit is a snapshot of your project at a particular point in time. Each commit includes a unique identifier, a message describing changes, and reference to parent commit.
3. Branches
Branches allow you to work on different features or parts of your project simultaneously without affecting the main development line (usually called the "master" branch).
4. Pull Requests (PRs)
In Git-based collaboration workflows (GitHub/GitLab), pull requests are a way for developers to propose changes and have them reviewed by their peers.
5. Merging
Merging involves combining changes from one branch (or multiple branches) into another when changes are ready to be incorporated into the main branch.
6. Remote Repositories
Copies of your project stored on a different server (GitHub, GitLab, Bitbucket). Developers collaborate by pushing their changes and pulling updates from it.
7. Cloning
The process of creating a copy of a remote repository on your local machine, allowing you to work on the project and make changes locally.
8. Forking
A way to create your own copy of a repository on a hosting platform like GitHub, make changes, and later create pull requests to contribute back.
Decoration

Features of Git

Git is an essential tool in software development and for many other collaborative and version-controlled tasks. The key reasons why Git is crucial include:

1
Version Control: Track changes in files over time with full history for debugging and auditing.
2
Collaboration: Multiple developers work on the same project simultaneously with conflict resolution.
3
Branching: Isolated environments for new features or bug fixes without affecting main code.
4
Distributed Development: Every developer has a complete copy of project history locally.
5
Backup & Recovery: Distributed redundancy across machines makes data recovery seamless.
6
Code Review: Built-in mechanisms on GitHub/GitLab to propose changes and comment on code.
7
Open Source Development: Industry standard for global community forks and contributions.
8
Efficiency: Stores file changes and snapshots with small repository sizes and high speed.
9
History & Documentation: Commit messages serve as permanent project documentation.
10
Customizability: Configurable hooks and scripts to automate workflows and enforce standards.

Version Control System (VCS): Centralized vs Distributed

Centralized VCS (CVCS) - e.g. CVS, Subversion (SVN) Distributed VCS (DVCS) - e.g. Git, Mercurial, Bazaar
Single central repository stores all files and version history. Every developer has a complete copy of repository and full history.
Developers check out files, make changes, and commit back over network. Developers work independently offline, create branches, and synchronize.
Decoration

Life Cycle of Git

The Git lifecycle refers to the typical sequence of actions and steps you take when using Git to manage your source code and collaborate with others:

1
Initializing a Repository: Start using Git by initializing a repo in project directory via git init.
2
Working Directory: Project files you are actively modifying exist in the working directory.
3
Staging: Select changes for the next commit using git add <file> or git add ..
4
Committing: Create snapshots with an explanation using git commit -m "msg".
5
Local Repository: Commits are permanently preserved in your local .git repository.
6
Branching: Create isolated branches using git branch and git checkout.
7
Merging: Integrate work from a branch into master using git merge.
8
Remote Repository: Central hub on servers (GitHub/GitLab) used for team code sharing.
9
Pushing: Upload local commits to remote repository using git push.
10
Pulling: Fetch and merge remote changes to local repository using git pull.
11
Conflict Resolution: Manually resolve overlapping edits when Git notifies of conflicts.
12
Collaboration: Collaborate via pull requests and code reviews on shared repositories.
13
Tagging & Releases: Create version tags using git tag to mark significant milestones.
14
Continuous Cycle: Repeat these steps to manage the ongoing evolution of your project.
Decoration

2. Git Installation

1. Installing Git on Windows

a. Using Git for Windows (Git Bash): Go to gitforwindows.org, download the installer, and follow the installation wizard.

b. Using GitHub Desktop (Optional): If you prefer a GUI, download from desktop.github.com.

2. Installing from Source & Verification

Download source code from git-scm.com/downloads and follow compilation steps.

Verification Command:

$git --version
# Output: git version 2.44.0

To Configure the Git

Configuring Git involves setting up your identity (your name and email), customizing Git options, and configuring remote repositories. Git has three levels of configuration: system, global, and repository-specific.

bash - Configuration Commands
# 1. System Configuration (affects all users, stored in /etc/gitconfig)
$git config --system user.name "Your Name"
$git config --system user.email "your.email@example.com"

# 2. Global Configuration (applies to your user account, stored in ~/.gitconfig)
$git config --global user.name "Your Name"
$git config --global user.email "your.email@example.com"

# View your global Git configuration
$git config --global --list
Decoration

3. Git Commands List

Git is a popular version control system used for tracking changes in software development projects. Here is a list of common Git commands along with brief explanations:

# Command Syntax Description & Explanation
1 git init Initializes a new Git repository in the current directory.
2 git clone <repository URL> Creates a copy of a remote repository on your local machine.
3 git add <file> Stages a file to be committed, marking it for tracking in the next commit.
4 git commit -m "message" Records the changes you've staged with a descriptive commit message.
5 git status Shows the status of your working directory and the files modified or staged.
6 git log Displays a log of all previous commits, including hashes, authors, and dates.
7 git diff Shows the differences between working directory and the last committed version.
8 git branch Lists all branches in the repository and highlights currently checked-out branch.
9 git branch <branchname> Creates a new branch with the specified name.
10 git checkout <branchname> Switches to a different branch.
11 git merge <branchname> Merges changes from specified branch into currently checked-out branch.
12 git pull Fetches changes from remote repository and merges them into current branch.
13 git push Pushes your local commits to a remote repository.
14 git remote Lists the remote repositories that your local repository is connected to.
15 git fetch Retrieves changes from a remote repository without merging them.
16 git reset <file> Unstages a file that was previously staged for commit.
17 git reset --hard <commit> Resets branch to specific commit, discarding all changes after that commit.
18 git stash Temporarily saves your changes to a "stash" so you can switch branches.
19 git tag Lists and manages tags (usually used for marking points in history, like releases).
20 git blame <file> Shows who made each change to a file and when.
21 git rm <file> Removes a file from both your working directory and the Git repository.
22 git mv <oldfile> <newfile> Renames a file and stages the change.
Decoration
EXPERIMENT 1 Setting Up and Basic Commands
Aim / Problem Statement
Initialize a new Git repository in a directory. Create a new file and add it to the staging area and commit the changes with an appropriate commit message.

Solution & Procedure

To initialize a new Git repository in a directory, create a new file, add it to the staging area, and commit the changes with an appropriate commit message, follow these steps:

1
Open your terminal and navigate to the directory where you want to create the Git repository.
2
Initialize a new Git repository in that directory using git init.
3
Create a new file in the directory. For example, let's create a file named "my_file.txt." You can use any text editor or command-line tools to create the file.
4
Add the newly created file to the staging area using git add my_file.txt. This command stages the file for the upcoming commit.
5
Commit the changes with an appropriate commit message. Your commit message should briefly describe the purpose or nature of changes made.
bash - Experiment 1 Commands
$git init

$git add my_file.txt

$git commit -m "Add a new file called my_file.txt"

After these steps, your changes will be committed to the Git repository with the provided commit message. You now have a version of the repository with the new file and its history stored in Git.

Decoration
EXPERIMENT 2 Creating and Managing Branches
Aim / Problem Statement
Create a new branch named "feature-branch." Switch to the "master" branch. Merge the "feature-branch" into "master."

Solution & Procedure

To create a new branch named "feature-branch," switch to the "master" branch, and merge the "feature-branch" into "master" in Git, follow these steps:

1
Make sure you are in the "master" branch by switching to it: git checkout master
2
Create a new branch named "feature-branch" and switch to it using: git checkout -b feature-branch
3
Make your changes in the "feature-branch" by adding, modifying, or deleting files as needed.
4
Stage and commit your changes in the "feature-branch" using git add . and git commit -m "Your commit message for feature-branch".
5
Switch back to the "master" branch using: git checkout master
6
Merge the "feature-branch" into the "master" branch: git merge feature-branch
bash - Experiment 2 Commands
$git checkout master

$git checkout -b feature-branch

$git add .
$git commit -m "Your commit message for feature-branch"

$git checkout master

$git merge feature-branch

Now, your changes from the "feature-branch" have been merged into the "master" branch. Your project's history will reflect the changes made in both branches.

Decoration
EXPERIMENT 3 Creating and Managing Branches
Aim / Problem Statement
Write the commands to stash your changes, switch branches, and then apply the stashed changes.

Solution & Procedure

To stash your changes, switch branches, and then apply the stashed changes in Git, you can use the following commands:

1
Stash your changes:
$ git stash save "Your stash message"
This command will save your changes in a stash, which acts like a temporary storage for changes that are not ready to be committed.
2
Switch to the desired branch:
$ git checkout target-branch
Replace "target-branch" with the name of the branch you want to switch to.
3
Apply the stashed changes:
$ git stash apply
This command will apply the most recent stash to your current working branch. If you have multiple stashes, you can specify a stash by name or reference (e.g., git stash apply stash@{2}) if needed.
bash - Experiment 3 Commands
$git stash save "Your stash message"

$git checkout target-branch

$git stash apply
If you want to remove the stash after applying it, you can use git stash pop instead of git stash apply. Remember to replace "Your stash message" and "target-branch" with the actual message and branch name.
Decoration
EXPERIMENT 4 Collaboration and Remote Repositories
Aim / Problem Statement
Clone a remote Git repository to your local machine.

Solution & Procedure

To clone a remote Git repository to your local machine, follow these steps:

1
Open your terminal or command prompt.
2
Navigate to the directory where you want to clone the remote Git repository. You can use the cd command to change your working directory.
3
Use the git clone command to clone the remote repository. Replace <repository_url> with the URL of the remote Git repository you want to clone.
4
Git will clone the repository to your local machine. Once the process is complete, you will have a local copy of the remote repository in your chosen directory.
bash - Experiment 4 Commands
$git clone <repository_url>

# Full Example:
$git clone https://github.com/username/repo-name.git

Replace https://github.com/username/repo-name.git with the actual URL of the repository you want to clone. You can now work with the cloned repository on your local machine, make changes, and push those changes back to the remote repository as needed.

Decoration
EXPERIMENT 5 Collaboration and Remote Repositories
Aim / Problem Statement
Fetch the latest changes from a remote repository and rebase your local branch onto the updated remote branch.

Solution & Procedure

To fetch the latest changes from a remote repository and rebase your local branch onto the updated remote branch in Git, follow these steps:

1
Open your terminal or command prompt.
2
Make sure you are in the local branch you want to rebase: $ git checkout <branch-name>
3
Fetch the latest changes from the remote repository without merging: $ git fetch origin
4
Rebase your local branch onto the updated remote branch: $ git rebase origin/<branch-name> (This reapplies your local commits on top of remote changes).
5
Resolve any conflicts that may arise. Git will notify you. Use a text editor to edit conflicting files, save changes, and continue: $ git rebase --continue
6
After resolving conflicts and completing rebase, your local branch is updated.
7
Push your rebased changes to remote: $ git push origin <branch-name>
bash - Experiment 5 Commands
$git checkout <branch-name>

$git fetch origin

$git rebase origin/<branch-name>

$git rebase --continue

$git push origin <branch-name>
Decoration
EXPERIMENT 6 Collaboration and Remote Repositories
Aim / Problem Statement
Write the command to merge "feature-branch" into "master" while providing a custom commit message for the merge.

Solution & Procedure

To merge the "feature-branch" into "master" in Git while providing a custom commit message for the merge, you can use the following command:

bash - Experiment 6 Commands
$git checkout master

$git merge feature-branch -m "Your custom commit message here"

Replace "Your custom commit message here" with a meaningful and descriptive commit message for the merge. This message will be associated with the merge commit that is created when you merge "feature-branch" into "master."

Summary: By using the -m flag, Git creates the merge commit with your specified message directly, rather than opening your default text editor (like vim or nano) to prompt for a message.
Decoration
EXPERIMENT 7 Git Tags and Releases
Aim / Problem Statement
Write the command to create a lightweight Git tag named "v1.0" for a commit in your local repository.

Solution & Procedure

To create a lightweight Git tag named "v1.0" for a commit in your local repository, you can use the following command:

bash - Experiment 7 Commands
$git tag v1.0

# Tagging a specific historical commit:
$git tag v1.0 <commit-SHA>

This command will create a lightweight tag called "v1.0" for the most recent commit in your current branch. If you want to tag a specific commit other than the most recent one, you can specify the commit's SHA-1 hash after the tag name. Replace <commit-SHA> with the actual SHA-1 hash of the commit you want to tag.

Lightweight vs Annotated Tags: A lightweight tag is like a branch that doesn’t change—it’s just a pointer to a specific commit. To push tags to a remote repository, use git push origin v1.0 or git push origin --tags.
Decoration
EXPERIMENT 8 Advanced Git Operations
Aim / Problem Statement
Write the command to cherry-pick a range of commits from "source-branch" to the current branch.

Solution & Procedure

To cherry-pick a range of commits from "source-branch" to the current branch, you can use the following command:

bash - Experiment 8 Commands
$git cherry-pick <start-commit>^..<end-commit>

# Example using specific commit hashes:
$git cherry-pick ABC123^..DEF456

Replace <start-commit> with the commit at the beginning of the range, and <end-commit> with the commit at the end of the range. The ^ symbol is used to exclude the <start-commit> itself and include all commits after it up to and including <end-commit>. This will apply the changes from the specified range of commits to your current branch.

For example, if you want to cherry-pick a range of commits from "source-branch" starting from commit ABC123 and ending at commit DEF456, you would use git cherry-pick ABC123^..DEF456. Make sure you are on the branch where you want to apply these changes before running the cherry-pick command.

Decoration
EXPERIMENT 9 Analysing and Changing Git History
Aim / Problem Statement
Given a commit ID, how would you use Git to view the details of that specific commit, including the author, date, and commit message?

Solution & Procedure

To view the details of a specific commit, including the author, date, and commit message, you can use the git show or git log command with the commit ID. Here are both options:

1
Using git show:
$ git show <commit-ID>
Replace <commit-ID> with the actual commit ID you want to view. This command will display detailed information about the specified commit, including the commit message, author, date, and the changes introduced by that commit. (e.g., $ git show abc123).
2
Using git log:
$ git log -n 1 <commit-ID>
The -n 1 option tells Git to show only one commit. Replace <commit-ID> with the actual commit ID. This command will display a condensed view of the specified commit, including its commit message, author, date, and commit ID. (e.g., $ git log -n 1 abc123).
bash - Experiment 9 Commands
# 1. Using git show (Metadata + Diff)
$git show abc123

# 2. Using git log (Condensed Header View)
$git log -n 1 abc123

Both of these commands will provide you with the necessary information about the specific commit you're interested in.

Decoration
EXPERIMENT 10 Analysing and Changing Git History
Aim / Problem Statement
Write the command to list all commits made by the author "JohnDoe" between "2023-01-01" and "2023-12-31."

Solution & Procedure

To list all commits made by the author "JohnDoe" between "2023-01-01" and "2023-12-31" in Git, you can use the git log command with the --author and --since and --until options. Here's the command:

bash - Experiment 10 Commands
$git log --author="JohnDoe" --since="2023-01-01" --until="2023-12-31"

This command will display a list of commits made by the author "JohnDoe" that fall within the specified date range, from January 1, 2023, to December 31, 2023. Make sure to adjust the author name and date range as needed for your specific use case.

Query Flags: You can also combine this with --oneline to get a concise list of commit hashes and commit messages without full timestamp headers.
Decoration
EXPERIMENT 11 Analysing and Changing Git History
Aim / Problem Statement
Write the command to display the last five commits in the repository's history.

Solution & Procedure

To display the last five commits in a Git repository's history, you can use the git log command with the -n option, which limits the number of displayed commits. Here's the command:

bash - Experiment 11 Commands
$git log -n 5

This command will show the last five commits in the repository's history. You can adjust the number after -n to display a different number of commits if needed (e.g. git log -n 10).

Alternative Syntax: You can also write git log -5 as a shorthand for git log -n 5.
Decoration
EXPERIMENT 12 Analysing and Changing Git History
Aim / Problem Statement
Write the command to undo the changes introduced by the commit with the ID "abc123".

Solution & Procedure

To undo the changes introduced by a specific commit with the ID "abc123" in Git, you can use the git revert command. The git revert command creates a new commit that undoes the changes made by the specified commit, effectively "reverting" the commit. Here's the command:

bash - Experiment 12 Commands
$git revert abc123

Replace "abc123" with the actual commit ID that you want to revert. After running this command, Git will create a new commit that negates the changes introduced by the specified commit. This is a safe way to undo changes in Git because it preserves the commit history and creates a new commit to record the reversal of the changes.

Revert vs Reset: git revert is non-destructive and safe for shared remote branches, whereas git reset rewrites history by moving the branch pointer backwards.
Decoration

Notes