MTMC-509: Programming Lab
Lab 2: Version Control with Git & GitHub
Objective:
• To understand basic Git commands.
• To work with branches and resolve conflicts.
• To integrate local Git with GitHub for remote collaboration.
Part A : Local Git Practice
1. Repository Setup
o Create a folder named git_lab.
o Initialize Git in this folder.
o Verify initialization.
➔ PS D:\NIT JALANDHAR\Git Lab> mkdir git_lab
➔ Directory: D:\NIT JALANDHAR\Git Lab
➔
➔ Mode LastWriteTime Length Name
➔ ---- ------------- ------ ----
➔ d----- 13-Sep-25 7:36 PM git_lab
➔
➔ PS D:\NIT JALANDHAR\Git Lab> ls
➔ Directory: D:\NIT JALANDHAR\Git Lab
➔
➔ Mode LastWriteTime Length Name
➔ ---- ------------- ------ ----
➔ d----- 13-Sep-25 7:36 PM git_lab
➔
➔ PS D:\NIT JALANDHAR\Git Lab> cd git_lab
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git init
➔ Initialized empty Git repository in D:/NIT JALANDHAR/Git
➔ Lab/git_lab/.git
➔
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git status
➔ On branch main
➔ No commits yet
➔ nothing to commit (create/copy files and use "git add" to track)
2. Basic File Operations
o Create a file hello.txt and write the line:
“Welcome to Git”
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> pwd
➔
➔ Path
➔ ----
➔ D:\NIT JALANDHAR\Git Lab\git_lab
➔
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> ls
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> echo "" > hello.txt
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> ls
➔
➔ Directory: D:\NIT JALANDHAR\Git Lab\git_lab
➔
➔ Mode LastWriteTime Length Name
➔ ---- ------------- ------ ----
➔ -a---- 13-Sep-25 9:38 PM 6 hello.txt
➔
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> echo "Welcome to GIT" >
hello.txt
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> cat hello.txt
➔ Welcome to GIT
o Add the file to staging area and commit with the message:
“Add hello.txt with welcome message “
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git status
➔ On branch main
➔ No commits yet
➔ Untracked files:
➔ (use "git add <file>..." to include in what will be committed)
➔ hello.txt
➔ nothing added to commit but untracked files present (use
"git add" to track)
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git add hello.txt
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git status
➔ On branch main
➔ No commits yet
➔ Changes to be committed:
➔ (use "git rm --cached <file>..." to unstage)
➔ new file: hello.txt
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git commit -m
"Adding hello.txt with a Welcome message"
➔ [main (root-commit) 809853d] Adding hello.txt with a
Welcome message
➔ 1 file changed, 0 insertions(+), 0 deletions(-)
➔ create mode 100644 hello.txt
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git status
➔ On branch main
➔ nothing to commit, working tree clean
o Append a new line to the same file: “Learning Git basics”
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> cat hello.txt
➔ Welcome to GIT
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> echo "Learning GIT Basics"
>> hello.txt
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> cat hello.txt
➔ Welcome to GIT
➔ Learning GIT Basics
o Commit with the message: Update hello.txt with learning
message
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git status
➔ On branch main
➔ Changes not staged for commit:
➔ (use "git add <file>..." to update what will be committed)
➔ (use "git restore <file>..." to discard changes in working directory)
➔ modified: hello.txt
➔
➔ no changes added to commit (use "git add" and/or "git commit -a")
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git add hello.txt
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git status
➔ On branch main
➔ Changes to be committed:
➔ (use "git restore --staged <file>..." to unstage)
➔ modified: hello.txt
➔
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git commit -m "Update
hello.txt with learning message"
➔ [main 92c8ab3] Updaate hello.txt with learning message
➔ 1 file changed, 0 insertions(+), 0 deletions(-)
3. Branching and Merging
o Create a branch feature.
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> pwd
➔
➔ Path
➔ ----
➔ D:\NIT JALANDHAR\Git Lab\git_lab
➔
➔
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git branch feature
o In this branch, create a new file feature.txt with the
content: “This is a feature branch”
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git checkout feature
➔ Switched to branch 'feature'
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> echo "This is a Feature Branch"
> feature.txt
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git add feature.txt
o Commit the changes.
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git commit -m "Add feature.txt
in feature branch"
➔ [feature 33ade60] Add feature.txt in feature branch
➔ 1 file changed, 0 insertions(+), 0 deletions(-)
➔ create mode 100644 feature.txt
o Switch back to main and merge feature into it.
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git branch
➔ * feature
➔ main
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git checkout main
➔ Switched to branch 'main'
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git branch
➔ feature
➔ * main
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git merge feature
➔ Updating 92c8ab3..33ade60
➔ Fast-forward
➔ feature.txt | Bin 0 -> 54 bytes
➔ 1 file changed, 0 insertions(+), 0 deletions(-)
➔ create mode 100644 feature.txt
4. Conflict Simulation and Resolution
o Create a new branch conflict-branch.
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git branch
➔ feature
➔ * main
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git branch conflict-branch
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git branch
➔ conflict-branch
➔ feature
➔ * main
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git checkout conflict-
branch
➔ Switched to branch 'conflict-branch'
o Edit hello.txt to add the line:
“This line is from CONFLICT branch.”
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> echo "This line is from
CONFLICT branch" >> hello.txt
o Commit the changes.
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git status
➔ On branch conflict-branch
➔ Changes not staged for commit:
➔ (use "git add <file>..." to update what will be committed)
➔ (use "git restore <file>..." to discard changes in working directory)
➔ modified: hello.txt
➔
➔ no changes added to commit (use "git add" and/or "git commit -a")
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git add hello.txt
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git status
➔ On branch conflict-branch
➔ Changes to be committed:
➔ (use "git restore --staged <file>..." to unstage)
➔ modified: hello.txt
➔
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git commit -m "Add conflict
line in hello.txt"
➔ [conflict-branch 5842721] Add conflict line in hello.txt
➔ 1 file changed, 0 insertions(+), 0 deletions(-)
o Switch back to main and add another line at the end of
hello.txt: “This line is from MAIN branch.”
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git branch
➔ * conflict-branch
➔ feature
➔ main
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git checkout main
➔ Switched to branch 'main'
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> echo "This line is from
the MAIN branch" >> hello.txt
o Commit the changes.
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git status
➔ On branch main
➔ Changes not staged for commit:
➔ (use "git add <file>..." to update what will be committed)
➔ (use "git restore <file>..." to discard changes in working directory)
➔ modified: hello.txt
➔
➔ no changes added to commit (use "git add" and/or "git commit -a")
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git add hello.txt
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git status
➔ On branch main
➔ Changes to be committed:
➔ (use "git restore --staged <file>..." to unstage)
➔ modified: hello.txt
➔
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git commit -m "Add main
line in hello.txt"
➔ [main 99fbbc7] Add main line in hello.txt
➔ 1 file changed, 0 insertions(+), 0 deletions(-)
o Merge conflict-branch into main.
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git branch
➔ conflict-branch
➔ feature
➔ * main
➔ PS D:\NIT JALANDHAR\Git Lab\git_lab> git merge conflict-branch
➔ warning: Cannot merge binary files: hello.txt (HEAD vs. conflict-
branch)
➔ Auto-merging hello.txt
➔ CONFLICT (content): Merge conflict in hello.txt
➔ Automatic merge failed; fix conflicts and then commit the result.
o Resolve the merge conflict so the final hello.txt contains:
Welcome to Git
Learning Git basics
This line is from MAIN branch.
This line is from CONFLICT branch.
o Commit the resolved merge.
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> cat hello.txt
➔ Welcome to Git
➔ Learning Git basics
➔ This line is from MAIN branch
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> echo "THis line is from
CONFLICT branch" >> hello.txt
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> cat hello.txt
➔ Welcome to Git
➔ Learning Git basics
➔ This line is from MAIN branch
➔ THis line is from CONFLICT branch
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> git status
➔ On branch main
➔ You have unmerged paths.
➔ (fix conflicts and run "git commit")
➔ (use "git merge --abort" to abort the merge)
➔
➔ Unmerged paths:
➔ (use "git add <file>..." to mark resolution)
➔ both modified: hello.txt
➔
➔ no changes added to commit (use "git add" and/or "git commit -a")
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> git add hello.txt
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> git status
➔ On branch main
➔ All conflicts fixed but you are still merging.
➔ (use "git commit" to conclude merge)
➔
➔ Changes to be committed:
➔ modified: hello.txt
➔
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> git commit -m "Resolved
merge conflicts in hello.txt"
➔ [main e7a793e] Resolved merge conflicts in hello.txt
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> git status
➔ On branch main
➔ nothing to commit, working tree clean
Part B: GitHub Integration
5. Remote Repository Setup
o On GitHub, create a repository named git_lab
(without README).
o Connect the local repository with GitHub using git remote
add origin.
o Push the local main branch to GitHub.
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> git branch
➔ conflict-branch
➔ feature
➔ * main
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> git remote add origin
https://github.com/Akash7762/git_lab.git
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> git branch -M main
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> git push -u origin main
➔ info: please complete authentication in your browser...
➔ Enumerating objects: 18, done.
➔ Counting objects: 100% (18/18), done.
➔ Delta compression using up to 8 threads
➔ Compressing objects: 100% (15/15), done.
➔ Writing objects: 100% (18/18), 1.62 KiB | 127.00 KiB/s, done.
➔ Total 18 (delta 4), reused 0 (delta 0), pack-reused 0 (from 0)
➔ remote: Resolving deltas: 100% (4/4), done.
➔ To https://github.com/Akash7762/git_lab.git
➔ * [new branch] main -> main
➔ branch 'main' set up to track 'origin/main'.
6. Working with Remote
o Verify files (hello.txt, feature.txt) and commit history appear
on GitHub.
o On GitHub (web), create a new branch extra-branch.
o Add a file extra.txt with the content:
“Added from GitHub directly”
o Switch back to your local machine and pull the changes using:
git pull origin main
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> git status
➔ On branch main
➔ Your branch is up to date with 'origin/main'.
➔
➔ nothing to commit, working tree clean
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> git pull origin main
➔ From https://github.com/Akash7762/git_lab
➔ * branch main -> FETCH_HEAD
➔ Already up to date.
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> git checkout extra-branch
➔ error: pathspec 'extra-branch' did not match any file(s) known to git
➔
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> git pull origin extra-branch
➔ remote: Enumerating objects: 4, done.
➔ remote: Counting objects: 100% (4/4), done.
➔ remote: Compressing objects: 100% (2/2), done.
➔ remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
➔ Unpacking objects: 100% (3/3), 992 bytes | 2.00 KiB/s, done.
➔ From https://github.com/Akash7762/git_lab
➔ * branch extra-branch -> FETCH_HEAD
➔ * [new branch] extra-branch -> origin/extra-branch
➔ Updating e7a793e..0d2f265
➔ Fast-forward
➔ extra.txt | 1 +
➔ 1 file changed, 1 insertion(+)
➔ create mode 100644 extra.txt
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> ls
➔
➔
➔ Directory: D:\NIT JALANDHAR\GIT_LAB\git_lab
➔
➔
➔ Mode LastWriteTime Length Name
➔ ---- ------------- ------ ----
➔ -a---- 16-Sep-25 4:05 PM 28 extra.txt
➔ -a---- 15-Sep-25 11:45 PM 54 feature.txt
➔ -a---- 16-Sep-25 12:00 AM 208 hello.txt
➔
➔
➔ PS D:\NIT JALANDHAR\GIT_LAB\git_lab> cat extra.txt
➔ Added from Github directly
Submission Guidelines
• Submit the GitHub repository link.
➔ https://github.com/Akash7762/git_lab
• Repository must include:
o hello.txt with resolved conflict text.
o feature.txt.
o extra.txt (added from GitHub).
o Complete commit history.