Practical 4
Practical Title:
To apply GitHub-based collaboration techniques including merging and remote
repository management
Theory:
1. What is Merging in Git?
Merging in Git is the process of combining changes from one branch into another branch
(usually into the main branch).
It helps integrate work done by different developers.
2. Types of Merge: (Fast-forward, Three-way merge)
Fast-Forward Merge
• Happens when there is no new commit in main branch
• Simply moves pointer forward
• No merge commit created
Three-Way Merge
• Happens when both branches have new commits
• Creates a new merge commit
• Combines histories of both branches
3. What is Remote Repository?
A remote repository is a version of your project stored on the internet (like on GitHub).
It allows collaboration and backup of code.
4. Common Remote Commands:
git remote: shows connected repositories
git push: upload local changes to remote
git pull: download + merge changes
git fetch: download changes only
Procedure:
Step 1: Create Local Repository
Step 2: Add Remote Repository
Step 3: Create Branch and Commit Changes
Step 4: Push Branch to Remote
Step 5: Merge Branch into Main
Step 6: Push Merged Code
Step 7: Fetch and Pull Updates
Activity / Task:
Task 1:
Create a remote repository and link it with local repository.
Repository Link: [Link]
__________________________________________
Task 2:
Perform branch merging and push changes to GitHub.
Commands Used:
• git init
• git remote add origin [Link]
• git checkout -b feature-branch
• git add [Link]
• git commit -m "Initial commit in feature branch"
• git push origin feature-branch
• git checkout -b main
• git merge feature-branch
• git push origin main
• git fetch origin
• git pull origin main
__________________________________________
Task 3:
Explain difference between git fetch and git pull.
• git fetch:
- Downloads the latest changes from the remote repository.
- Does not merge the changes into the local branch.
- Used to check updates safely before applying them.
• git pull:
- Downloads changes and automatically merges them into the local branch.
- It is a combination of git fetch and git merge.
- Used to update the local repository directly.
__________________________________________
Advantages:
1. Easy Collaboration
2. Centralized code storage
3. Version tracking
4. Backup of data
5. Supports teamwork
Challenges:
1. Merge conflicts
2. Requires internet for remote operations
3. Learning Git commands