Back to Home
Git
Branch management and merging strategies
branchesmergerebaseworkflow
Git Branching
Commands for branch management and merging.
Branch Operations
# List branches
git branch
git branch -a # Include remote branches
# Create a branch
git branch feature-name
# Switch to branch
git checkout feature-name
git switch feature-name # Modern alternative
# Create and switch
git checkout -b feature-name
git switch -c feature-name
# Delete branch
git branch -d feature-name
git branch -D feature-name # Force delete
Merging
# Merge branch into current
git merge feature-name
# Merge with no fast-forward
git merge --no-ff feature-name
# Abort merge
git merge --abort
Rebasing
# Rebase current branch onto main
git rebase main
# Interactive rebase (last 3 commits)
git rebase -i HEAD~3
# Continue after resolving conflicts
git rebase --continue
# Abort rebase
git rebase --abort
Remote Branches
# Fetch remote branches
git fetch origin
# Track remote branch
git checkout -b local-branch origin/remote-branch
# Push new branch to remote
git push -u origin feature-name
# Delete remote branch
git push origin --delete feature-name