This project demonstrates the practical use of Git version control while developing a simple Calculator application in Java. The focus of the assignment is not only on coding but also on understanding Git commands, branching strategy, merging techniques, and merge conflict resolution.
The project was developed using:
- IDE: Eclipse
- Version Control: Git (Git Bash)
- Remote Repository: GitHub
git init- Initializes a new Git repository in the project directory.
- Creates a hidden
.gitfolder which tracks all changes in the project.
After initialization, all project files were added and committed using:
git add .
git commit -m "Initial calculator project"- main → Stable and final branch
- addition → Contains addition-related changes
- subtraction → Contains subtraction-related changes
- multiplication → Contains multiplication-related changes
git branch addition
git branch subtraction
git branch multiplication- Branching allows developers to work on different features independently.
- It avoids breaking the main codebase.
- Each operation of the calculator was implemented and tested in its own branch.
To switch between branches:
git checkout branch_nameEach branch contained independent commits related only to its feature.
After completing the work, branches were merged into main.
git stash
git stash popgit stashtemporarily saves uncommitted changes.git stash poprestores the saved changes back to the working directory.
This is useful when:
- You want to switch branches
- You are not ready to commit changes yet
git fetch origin
git pull origin main| Command | Description |
|---|---|
git fetch |
Downloads updates from remote but does not merge |
git pull |
Fetches and merges changes into current branch |
git checkout main
git merge additiongit mergecombines changes from one branch into another.- It creates a merge commit.
- If there are no conflicting changes, Git merges automatically.
During some merges, Git displayed:
Merge made by the 'ort' strategy.
-
ORT (Optimized Recursive Tree) is Git’s default merge strategy.
-
It automatically merges branches when:
- Changes are in different files, or
- Changes are on different lines of the same file.
-
No manual intervention is required when ORT succeeds.
A merge conflict occurs when:
- Two branches modify the same line of the same file differently.
- Git cannot decide which change to keep.
-
The same line in
Calculator.javawas modified in both:additionbranchsubtractionbranch
git merge subtractionGit response:
CONFLICT (content): Merge conflict in src/calculator/Calculator.java
Automatic merge failed; fix conflicts and then commit the result.
Git inserts conflict markers inside the file:
<<<<<<< HEAD
// code from current branch
=======
/ code from merging branch
>>>>>>> subtractionThese markers clearly indicate:
- Current branch changes
- Incoming branch changes
- Open the conflicted file in Eclipse
- Analyze both versions of code
- Decide the final correct logic
- Remove conflict markers
- Save the file
git add src/calculator/Calculator.java
git commit -m "Resolved merge conflict in Calculator.java"This completes the conflict resolution process.
git checkout multiplication
git rebase main
git checkout main
git merge multiplicationgit rebasereapplies commits on top of another branch- Creates a linear and clean commit history
- Avoids unnecessary merge commits
| Command | Purpose |
|---|---|
git status |
Shows current working tree status |
git log --oneline --graph |
Displays commit history visually |
git branch -d branch_name |
Deletes merged branches |
These were mentioned in class comments for shared understanding.
This project successfully demonstrates:
- Git repository setup
- Feature-based branching strategy
- Use of stash, fetch, pull
- Merge using
git mergeandgit rebase - Intentional creation and resolution of merge conflicts
- Proper version control practices using Git and GitHub
The assignment helped in gaining hands-on experience with real-world Git workflows