top of page

Version controlling in Git

Updated: Mar 7



  1. 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."


  1. Difference between clone, fetch and pull

    1. git pull: It fetches and merges changes into the current branch.

    2. git fetch: This fetches changes but doesn’t merge it to the repository

    3. git clone: It copies the entire repository.

    Difference between clone, fetch and pull
    Difference between clone, fetch and pull
  2. 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

Same changes for both the developers
Same changes for both the developers
  1. 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.

Merge Conflicts
Merge Conflicts

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:

    1. Keep HEAD Changes

    2. Keep Incoming Changes

    3. 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

  1. 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.

Life cycle of a file
Life cycle of a file
  1. References

Recent Posts

See All

Comments


bottom of page