DevOps Lab Manual
Lab Program - 1: Git Basics
1. Git Basics Initialize a local Git repository inside a folder named git-lab.
Initialize a Git Repository
mkdir gitlab
cd gitlab
git init
2. Create a file info.txt, write a few lines in it, and perform the first commit.
Create info.txt and Add Content
echo "This is my first Git lab." > info.txt
echo "Git is a version control system." >> info.txt
git add info.txt
Stage and Commit the File
git commit -m "Initial commit with info.txt"
3. Modify the file info.txt, then view the difference using git diff.
Modify the File
echo "I am learning Git basics." >> info.txt
View the Difference
git diff info.txt
4. Check the status and history of your repository.
git status
git log
OUTPUT
Lab Program – 2 : Branching and Merging
1. Create a new branch called dev, switch to it, and add a new file dev.txt.
Create a new branch dev, switch to it, and add a new file
git checkout -b dev
echo "This is the dev branch" > dev.txt
git add dev.txt
git commit -m "Add dev.txt in dev branch"
Switch back to main and merge dev
git checkout main
git merge
2. Create a merge conflict:
Create another branch dev2 from main
git checkout -b dev2
3. Edit the same file in both main and dev2 branches.
Edit the same file (dev.txt) in both main and dev2 to create a conflict
echo "Change from dev2 branch" >> dev.txt
git add dev.txt
git commit -m "Edit dev.txt in dev2 branch”
4. Merge dev2 into main and resolve the conflict manually.
Switch to main and edit the same file
git merge dev2
Manually resolve the conflict
git add dev.txt
git commit -m "Resolved merge conflict between main and dev2"
OUTPUT
Lab Program - 3: Remote Repositories (GitHub)
1. Create a repository on GitHub, and connect your local repo to it using
Create a repository on GitHub
Go to https://github.com
Click on New repository
Name it something like lab3-repo and click Create repository
Connect your local repo to GitHub
mkdir lab3-repo
cd lab3-repo
git init
echo "This is Lab 3 for Remote Repositories" > README.md
git add README.md
git commit -m "Initial commit"
git remote add origin https://github.com/souravl13/lab3-repo.git
2. Push your local changes to the GitHub repository.
git branch -M main
git push -u origin main
3. Clone a GitHub repository and make changes locally
git clone https://github.com/sourvl13/lab3-repo.git
cd lab3-repo
echo "Adding more content to the lab" >> README.md
git add README.md
git commit -m "Updated README with more content"
git push origin main
OUTPUT
Lab Program - 4: Collaboration and Pull Requests
1. Fork a public repository, make changes, and raise a pull request (PR).
Fork a Repository
Go to any public GitHub repository (e.g., https://github.com/octocat/Hello-
World)
Click the "Fork" button at the top-right.
Clone the Forked Repo Locally
git clone https://github.com/<your-username>/<repo-name>.git
cd <repo-name>
Make Changes
echo "This is a test PR change" >> pr-test.txt
git add pr-test.txt
git commit -m "Added pr-test.txt for PR demo"
Push Changes and Raise PR
git push origin main
2. Add a collaborator to your GitHub repo.
Add Collaborator
Go to your repository on GitHub.
Settings → Collaborators → Add GitHub username → Send invitation.
Collaborator Clones the Repo
git clone https://github.com/<your-username>/<repo-name>.git
cd <repo-name>
3. Let them push changes and you review them.
Collaborator Makes Changes
echo "Collaborator contribution" >> collab.txt
git add collab.txt
git commit -m "Added collab.txt"
git push origin main
Review Changes
Go to Pull Requests or Commits → View changes → Comment or approve
them.
4. Create a .gitignore file and add rules to ignore .log, .env, and node_modules
Create .git ignore File
touch .gitignore
Add Rules
echo ".log" >> .gitignore
echo ".env" >> .gitignore
echo "node_modules/" >> .gitignore
Commit .gitignore
git add .gitignore
git commit -m "Added .gitignore to ignore .log, .env, and node_modules"
git push origin main
OUTPUT