All about git conflicts and how to resolve them.
Resources used in this video:
PPT: Canva Designed PPT
GitHub Docs: Docs
Understanding Git Conflicts !
Git conflicts occur when multiple changes are made to the same part of a file in different branches, and Git cannot automatically determine which change should take precedence. Conflicts are a normal part of collaborative development and typically arise during the process of merging or rebasing branches.
When Do Git Conflicts Occur?
Git conflicts can happen in several scenarios, such as:
Merging Branches: When two branches are merged, and the same file has been modified differently in each branch.
Rebasing: When rebasing a branch, if there are changes in the base branch that conflict with changes in the feature branch.
Cherry-Picking: Applying specific commits from one branch to another can cause conflicts if the changes overlap.
Pulling with Local Changes: Pulling changes from a remote repository when local changes haven't been committed.
Conflicts Resolution (Basic):
Resolving conflicts involves reviewing the conflicting changes and deciding how to merge them manually. Here are the steps to resolve conflicts:
Identify Conflicts: When a conflict occurs, Git will pause the merge or rebase process and notify you of the conflicts.
Open the Conflicting Files: Conflicting files will be marked in Git, showing conflict markers (<<<<<<<, =======, >>>>>>>) that indicate the conflicting changes.
Manually Resolve the Conflict: Edit the file to select the appropriate changes. You may keep one change, combine them, or make additional edits.
Mark the Conflict as Resolved: Once you have resolved the conflicts, add the resolved files using git add <file>.
Complete the Merge or Rebase: Continue with the merge or rebase process using git commit or git rebase --continue.