Bash
Git Merge
Merging and conflict resolution.
By EZ4Code Team
gitmerge
Code
#!/bin/bash
# Merge branch
git checkout main
git merge feature
# Merge options
git merge --no-ff feature # Preserve merge record
git merge --ff-only feature # Fast-forward only
git merge --squash feature # Squash into single commit
# Resolve conflicts
git merge feature
# Manually edit file on conflict
# <<<<<<< HEAD
# My changes
# =======
# Their changes
# >>>>>>> feature
# After resolving
git add .
git commit -m "Merge feature, resolve conflicts"
# Abort merge
git merge --abort
# View conflict files
git diff --name-only --diff-filter=U
# Rebase
git checkout feature
git rebase main # Rebase feature commits onto main
# Interactive rebase
git rebase -i HEAD~3 # Modify last 3 commits
# pick / squash / fixup / reword / drop
# Rebase conflict
git rebase --continue # After resolving continue
git rebase --skip # Skip current commit
git rebase --abort # Abort
# Merge strategy
git merge -X theirs feature # Choose theirs on conflict
git merge -X ours feature # Choose ours on conflict
# View merge graph
git log --oneline --graph --allExplanation
git merge merges branches; --no-ff preserves records; --squash squashes commits; conflicts must be resolved manually before committing.
More Bash Snippets
Variables and Arrays in Bash
Assign variables, use command substitution, and work with arrays in Bash.
File Operations
File and directory management.
Text Processing
Text processing with grep, sed, awk.
Loops
for and while loops.
Conditionals
if and case conditional statements.
Functions
Function definition and parameters.