Source Code Management
Course Code: CSE 2015
Slot: L14 L15
Name: Ishrit Rai
SEN No.: A86605224057
Faculty: Dr Monit Kapoor
INDEX
Lab Session 1: Git Fundamentals
Computer
A computer is any device capable of performing calculations, whether they are
logical or mathematical.
Program/Code
A program (or code) is a set of instructions, often organised as an algorithm, that
directs a computer to perform a speci c task.
Need for Managing Source Code
Modern applications, such as Spotify, consist of multiple programs working
together on both the frontend and backend to deliver a smooth user experience.
Regular updates are essential for:
• Fixing Bugs: Quickly resolving errors that may occur.
• Improving UI/UX: Enhancing the user interface and overall experience.
• Optimising Performance: Addressing and re ning issues for better
performance.
For programmers, e ective management of source code is crucial because:
• It ensures that all les remain in context throughout the lifecycle of the
program.
• It facilitates collaboration, allowing multiple developers to work together on a
shared codebase.
Tools for Source Code Management
1. Git:
A version control system that runs locally on your computer. Git helps track
changes and manage versions of your project.
2. GitHub:
A global, cloud-based platform that hosts Git repositories, enabling
developers to share, collaborate, and contribute to projects from anywhere in
the world.
Version
A version in version control represents a snapshot of your project at a speci c
moment in time. This snapshot allows you to review, revert, or compare changes
made throughout the development process.
Page 1
fi
ff
fi
fi
fi
Lab Practical 1
1. Installing Git Using Homebrew
Step 1: Visit section 1.5 of pro git document and navigate to macOS section
Step 2: Install Homebrew (if not already installed):
• Command:
• /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/
install.sh)"
• Description: Installs Homebrew, a package manager for macOS.
Page 2
Step 3: Install Git Using Homebrew:
• Command: brew install git
• Description: Installs Git via Homebrew
Page 3
Step 4; Verify Git Installation:
Page 4
2. Basic CLI Commands
1) Command: ls
Description: Lists all les and directories in the current directory.
2) Command: date
Description: shows the current date and time in a standard format
3) Command: clear
Description: The clear command in the CLI is used to clear all the current text and output
displayed in the terminal window.
Page 5
fi
4) Command: time
Description: The time command in the CLI is used to measure the execution time of a command
or program.
5) Command: rm hello.txt
Description: Removes the le hello.txt from the current directory.
6) Command: cat hello.txt
Description: The cat command (short for concatenate) is used to display the contents of a le.
7)Command: cd Desktop
Description: Changes the current working directory to the Desktop directory.
8)Command: ls
Description: Lists all les and directories in the current directory.
Page 6
fi
fi
fi
3. Vim Text Editor
1) Command: vi hi.txt
Description: Opens (or creates) the le hi.txt in the Vim text editor.
2) Command: i (Insert Mode)
Description: Enters insert mode in Vim to allow text input.
Page 7
fi
3) Command: esc
Description: Used to exit insert mode
Page 8
4) Command: :wq
Description: Saves the changes and exits the Vim editor.
Page 9
4. Git Commands
1. Command: git - - version
Description:The git --version command is used to check the installed version of Git on
your system.
The below les are not currently tracked by git
2. Command: git init
Description: Initializes a new Git repository in the current directory.
4. Command: git status
Description: Displays the current status of the working directory and staging area.
Page 10
fi
3.Command: git add testone.txt
Description: Adds testone.txt to the staging area in preparation for a commit.
5.Command: git commit -m "add le one"
Description: Commits the staged changes with the message "add le one”
Page 11
fi
fi
6.Command: git log
Description: Displays the commit history of the repository.
7. Command: git clone
Description: to obtain a copy of an existing Git repository
8. Command git con g --global user.name “Ishrit Rai”
Description: used to set up user name which will be linked to future commits
9. Command git con g --global email.id “[email protected]“
Description: used to set up email Id which will be linked to future commits.
Page 12
fi
fi
10. Command git con g - - list
Description: used to view all the settings
Page 13
fi
Lab Session 2: Git Commands
1. Command pwd
Description: returns the present working directory
2. Command ls
Description: lists all les and folders in the current directory
3. Command mkdir
Description: used to to make new directory/folder
4 .Command rmdir
Description: used to remove a directory
Page 14
fi
5. Command cd
Description: used to change current directory
6. Command cd ..
Description: used to exit the current sub directory
Page 15
Git commit
Step 1: create a le in the present working directory and add
content
Step 2: using git init initialise a hidden git repository for
tracking the les
Step 3: using git add move the le to staging area
Step 4: check git status for con rmation
Page 16
fi
fi
fi
fi
Step 5: commit the le to a local repository
Command ls-ah
Description: used to check hidden les in a directory
Command git rm --cached < le>
Description : used to remove le from staging area
Page 17
fi
fi
fi
fi
Lab Session 3: Git Di
Mount Point
Point from where we can access the desired folder directly
/Users/ishritrai/Library/Mobile Documents/com~apple~CloudDocs/Amity/Git_Amity/Lab_2
In the above le path mount point of Lab_2 is Git_Amity
Command touch < le_name>
Used to create a le without any content
Command git rm -rf < le_name>
Used to remove a le from git tracking
Page 18
fi
fi
fi
fi
fi
ff
Task 1: make two commits in a directory
Step 1: create two les with content in a directory
Step 2: use git add. Command to add both les in the staging
area
Step 3: use git commit -m to commit both les to local
repository
Step 4: use git log command to verify the commit history
Page 19
fi
fi
fi
Step 5: use git log- - oneline for generating shorter commit id
Page 20
Task 2: compare two commits in a directory
Use git di along with the commit id generated from git log - -
online
Page 21
ff
Lab Session 4: practice git di
Page 22
ff
Lab Session 5 : git remote
Make 4 commits and compare them using git di
Page 23
f
Use git remote command to establish a connection between
local Git repository and a remote repository
Use The git push command to transfer commits from a local
Git repository to a remote repository
Con rming the remote connection with git remote
Page 24
fi
Checking the commits made on GitHub account
Page 25
Lab Session 6 : git branching
Branch: pointer to a commit
Pointer: connects two memory address where at least one
variable must have an active memory address
Head: branch on which the last commit is made
Git branch command used to view the existing branches in the
git repository
Git checkout command used to switch the currently active
branch to another branch. Here we want to create a new
branch from a particular commit
Page 26
Git branch test_1: used to create branch with name test_1
Con rm the created branch by using git branch command to
view all the branches
Use git_checkout command to pivot to that particular branch
Make commits in test_1 branch
Page 27
fi
Viewing the commits on a particular branch
Git clone command used to create copy of an existing git
repository
Git pull is used to fetch and integrate changes which are in the
remote repository to local repository
Page 28
Git remote-v: used to view all remote repositories in a directory
Page 29
Page 30
Page 31
Page 32
Page 33
Page 34
Page 35
Page 36
Page 37
Page 38
Page 39
Page 40
Page 41
Page 42
Page 43
Page 44
Page 45
Page 46