Git Branching Explained: The Role of .gitignore in Version Control

GIT Branching Strategies

  • The master is considered as production version of the source code.

  • GIT branching strategies are used to maintain integrity/correctness of master branch.

  • GIT branches are logical copy of a repository (master branch).

  • GIT branching strategies prevents the conflict in master branch.

  • To perform parallel development.

Working with Branches

  • git branch <new_branch_name> - To create new branch

  • git switch <branch_name> - Switch to any existing branch

    • Alternate command - git checkout <branch_name>
  • git switch -c <new_branch_name> - To create and switch to new branch

    • Alternate command - git checkout -b <new_branch_name>
  • git branch - Used get the list of branches

  • git branch -M <Branch_name> - Rename Branch

  • git branch -D <Branch_name> - Delete the branch

  • git merge

    • Used to Merge the Changes to Target Branch

    • Should be executed from the target branch

    • syntax : git merge <branch_name>

GIT Merge Conflict

  • How Merge Conflict Occurs

    • When more than one user/feature try to update a same line in the same file on the same target branch, merge Conflict Occurs.

  • How to fix the Merge Conflict

    • Identify the file(s) causing the Merge Conflict

    • Open and review the file content

    • Upon review, decide which record should be retained or deleted from that file

    • Open the File in edit mode, and delete the header and footer lines, and update the file with required records and save it.

    • perform git add and commit to the target branch

  • Prevent the Merge Conflict

    • As per DevOps Process, review the Changes before merge

GIT IGNORE

  • Is used to Ignore the files from tracking!

  • create .gitignore file and commit in a repository as a very first commit.