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 branchLists all local branches in your repository.
git branch branch-nameCreates a new branch for developing features or fixes.
git checkout branch-nameSwitches to the specified branch.
git checkout -b branch-nameCreates a new branch and switches to it immediately.
git branch -m old-name new-nameRenames a branch, allowing you to update the branch name without affecting the history.
git branch -d branch-nameDeletes a branch that is no longer needed.
git push origin --delete branch-nameDeletes a branch on the remote repository.
git checkout main
git merge branch-nameMerges the specified branch into the current branch.
git checkout branch-name
git rebase mainRebases the current branch onto the main branch, creating a linear project history.
git branch -rLists remote branches, showing branches that exist on the remote repository.
git checkout -t origin/branch-nameCreates a local branch tracking a remote branch, synchronizing your local branch with the remote.