Working on a college software project becomes difficult when several students edit the same files. One teammate changes a login page, another updates its validation, and a third needs to prepare a demonstration. Sending ZIP files back and forth makes it hard to identify the latest working version. Git offers a better approach: record changes, develop features independently and combine reviewed work into a shared codebase.
This Git branching and merge conflicts tutorial explains the workflow through a small student project. You will create branches, reproduce a conflict safely, resolve it and learn how to present your work in a technical interview. You need only a terminal, Git and a text editor.
What is a Git branch?
Git is a distributed version control system. A commit records a snapshot of tracked project files together with information about its history. A branch is a movable reference to a commit. As you create commits on a branch, that reference advances. Branches allow developers to explore changes without immediately changing the main development line.
Imagine a student attendance application. The main branch contains a working version. A feature branch can introduce an attendance report while another branch improves the login form. Both developers can make progress independently. When the changes are ready, the team integrates them through a merge or another agreed integration workflow.
Git and GitHub are not the same thing
Git manages version history locally. GitHub and similar hosting services provide remote repositories, collaboration interfaces and review tools. You can practise every local command in this tutorial without creating an online account. A pull request is a hosting platform feature for proposing and reviewing changes, rather than a built-in Git command.
Set up a practice repository
Use a new directory instead of an existing assignment. This ensures that the exercise cannot interfere with your coursework. Check that Git is installed with git --version. Then create a repository with an explicitly named main branch.
mkdir attendance-demo
cd attendance-demo
git init -b main
echo Attendance Dashboard > dashboard.txt
git add dashboard.txt
git commit -m "Create attendance dashboard"
If Git requests your identity, configure your name and email using git config user.name and git config user.email with your own values, then repeat the commit. These repository-level settings avoid changing unrelated projects. Older Git installations may require creating the repository first and renaming its initial branch.
Run git status to confirm that the working tree is clean. Use git log --oneline to view the first commit. A clean working tree is a useful starting point because uncommitted edits can complicate switching branches and merging.
Create a feature branch
Suppose your assignment is to add a weekly report. Create a branch with a descriptive name and switch to it in one command.
git switch -c feature/weekly-report
echo Weekly Attendance Report > dashboard.txt
git add dashboard.txt
git commit -m "Add weekly report heading"
The new commit belongs to the feature branch history. The main branch still points to the original commit. Run git branch to list local branches; the asterisk identifies the current one. Switching back to main restores the tracked file to the version recorded there, provided local changes do not prevent the switch.
Why small commits matter
Keep each commit focused on one understandable change. For example, add report calculations separately from layout improvements. A reviewer can then identify the reason for a change and investigate a regression more easily. Avoid vague messages such as final update or latest code. A useful message describes the behaviour introduced or corrected.
Reproduce a merge conflict
A merge conflict occurs when Git cannot automatically reconcile changes. It does not mean that the repository is broken. To reproduce a simple conflict, switch to main and replace the same line that the feature branch changed.
git switch main
echo Student Attendance Overview > dashboard.txt
git add dashboard.txt
git commit -m "Improve dashboard heading"
git merge feature/weekly-report
Git should report a content conflict in dashboard.txt because both branches replaced the original heading differently. Run git status to identify the unmerged file. Open it in your editor. A typical conflict display resembles the following:
<<<<<<< HEAD
Student Attendance Overview
=======
Weekly Attendance Report
>>>>>>> feature/weekly-report
The first section represents the current branch in this ordinary merge. The second represents the incoming branch. Git may display additional context depending on its conflict style settings. Do not simply delete the incoming text or accept every change automatically. Consider the intended application behaviour and decide whether one version or a combination is appropriate.
Resolve the conflict and complete the merge
For this example, replace the entire conflict block with the heading Student Attendance Overview – Weekly Report. Save the file, ensuring that no conflict markers remain. Review the result and stage it.
git add dashboard.txt
git diff --cached
git status
git commit -m "Merge weekly report and resolve heading conflict"
git log --oneline --graph --all
The staged diff helps you inspect the resolution before recording it. The final log displays the relationship between the two development histories. In a real application, run the relevant automated tests and manually check the affected screen before committing. A successful merge only means Git has integrated the files; it does not guarantee that the application behaves correctly.
What if you need to cancel the merge?
If you started from a clean working tree and realise that you need more information, use git merge --abort while the merge is in progress. This attempts to restore the pre-merge state. It is not a general undo command for completed merges. Avoid destructive reset commands when you are unsure which changes are committed or backed up.
Apply branching to real student projects
For a Python library management system, assign separate branches to book search, borrowing rules and report generation. Agree on shared data structures before development. If two teammates change the same function, review both requirements together rather than treating the conflict as a competition between developers.
For a web application, separate API changes from user interface changes when practical. Document the expected request and response formats so that teammates can work independently. Before integration, verify that the frontend and backend still agree on those formats.
Teams using automated delivery pipelines can also run tests on proposed changes before merging. Madras Academy’s DevOps Engineering & CI/CD course covers Git alongside repeatable software delivery workflows. Students interested in backend practice can explore Python Web Development with Flask & FastAPI and apply branching to a small API project.
Build good collaboration habits
- Agree on branch naming and review rules before starting a team assignment.
- Integrate small changes regularly rather than waiting until the submission deadline.
- Inspect differences before staging and committing files.
- Keep passwords, access tokens and private configuration out of repositories.
- Test merged behaviour and document important decisions in the project README.
When using a remote repository, fetch updates and inspect the current shared history before integrating changes. Follow the team’s chosen merge or rebase policy. Avoid rewriting shared history without agreement. These habits become particularly important when multiple people depend on the same codebase.
Turn this exercise into a portfolio project
Extend the attendance example into a small application with two independent features. Record the initial design, create feature branches, write tests and document one conflict resolution. Include a short explanation of why you chose the final behaviour. A clear repository history demonstrates collaboration and debugging skills beyond the finished interface.
During an interview, explain the difference between a branch, a commit and a merge. Describe how you inspect a conflict and validate the resolution. Students exploring deployment workflows can also consider Madras Academy’s Cloud & DevOps course to connect version control practice with broader infrastructure and delivery concepts.
Frequently asked questions
Does every merge create a merge commit?
No. If the current branch is an ancestor of the incoming branch, Git can often fast-forward its reference without creating a merge commit. Diverged histories normally require a merge commit when integrated through a regular merge.
Can Git merge different files automatically?
Usually, independent changes can be combined automatically. However, even an automatic merge can introduce logical incompatibilities, so testing remains essential.
Should beginners learn rebase immediately?
Start with branches, commits and ordinary merges. Learn rebase later in a disposable repository, because it recreates commits and can complicate collaboration when applied to shared history.
How can I practise without GitHub?
Use the local repository exercise above. Once comfortable, add a remote repository and practise review workflows with a teammate.
Take the next step with Madras Academy
Git branching and merge conflicts are practical skills for software development, testing and DevOps. Enquire with Madras Academy about suitable programming or DevOps training, discuss your current experience and choose a project-based learning path. Start by completing this exercise independently and explaining your resolution in your own words.




