Version controlling in Git
- Karan Bhakuni
- Dec 23, 2024
- 2 min read
Updated: Mar 7
Introduction
Version controlling is the backbone of modern software development. It enables the developers to collaborate seamlessly and maintain the proper history of their work. GitHub is the tool generally used in the organizations to maintain the track of their tasks and work done. Sometimes, it can be challenging to keep the track properly with so many commands and concepts. Understanding these key ideas is essential for streamlining workflows and avoiding common errors.
In this blog, we’ll break down some of the most frequently encountered Git concepts—like staying aligned with the latest changes, resolving conflicts, and tracking the journey of a file in your repository. Whether you’re a beginner or looking to level up your Git skills, this guide will help you navigate these topics with clarity and confidence."
Difference between clone, fetch and pull
git pull: It fetches and merges changes into the current branch.
git fetch: This fetches changes but doesn’t merge it to the repository
git clone: It copies the entire repository.
Difference between clone, fetch and pull Getting on the same head of the file
The remote collaboration is a major task to keep all the developers pointing to the same files.
git push, git pull, and git fetch are the commands which are used to synchronize changes made by the developers working on the remote repository

Merge Conflicts
A merge conflict occurs when Git cannot automatically combine changes from two branches because the same lines of code were edited differently. Merge Conflict generally occurs while merging branches using git merge.
Example:
Both Branch A and Branch B made different changes to a file1 then while merging the files the conflict occurs because of the the headers pointing to different heads.

Resolving a Merge Conflict
Step 1: Trigger the Conflict
git merge branch-B
If there’s a conflict, Git will pause the merge process and notify you of the conflicting files.
Step 2: Check the Conflict
git status
This shows the files with conflicts, marked as both modified.
Step 3: Open the Conflicted File
Decide how to merge the conflicting changes:
Keep HEAD Changes
Keep Incoming Changes
Combine Changes by editing the lines manually to merge them.
Step 5: Mark the Conflict as Resolved
After editing and saving the file, mark it as resolved:
git add <conflicted-file>
Step 6: Complete the Merge
git commit
Best Practices to prevent from these conflicts during merging
Pull Regularly: Always pull the latest changes before starting new work to reduce conflicts.
Commit Frequently: Avoid working on large changes for long periods without committing or merging.
Command | Purpose |
git status | List files with conflicts |
git add <conflicted-file> | Mark the file as resolved |
git commit | Complete the merge process |
git merge --abort | Abort the merge and return to the state before merging |
Life Cycle of a file
After the file comes to the git repository and is availed for the developers it goes through the different phases. The common phases through which the file flows is - untracked, modified, staged , committed.

References
Comments