Git Branch Management Commands
Posted on June 7, 2024 • 1 min read • 213 wordsMaster Git branch management with essential commands for creating, switching, merging, and deleting branches efficiently.
Effective branch management is crucial for a smooth development workflow. Here are essential commands for managing Git branches:
git branch
Lists all local branches in your repository.
git branch branch-name
Creates a new branch for developing features or fixes.
git checkout branch-name
Switches to the specified branch.
git checkout -b branch-name
Creates a new branch and switches to it immediately.
git branch -m old-name new-name
Renames a branch, allowing you to update the branch name without affecting the history.
git branch -d branch-name
Deletes a branch that is no longer needed.
git push origin --delete branch-name
Deletes a branch on the remote repository.
git checkout main
git merge branch-name
Merges the specified branch into the current branch.
git checkout branch-name
git rebase main
Rebases the current branch onto the main branch, creating a linear project history.
git branch -r
Lists remote branches, showing branches that exist on the remote repository.
git checkout -t origin/branch-name
Creates a local branch tracking a remote branch, synchronizing your local branch with the remote.