WE CODE NOW
  • Home 
  • Blog 
  • Guides 
Guides
  1. Home
  2. Guides
  3. Git
  4. Git Branch Management Commands

Git Branch Management Commands

Posted on June 7, 2024 • 1 min read • 213 words
Git
 
Branch Management
 
Version Control
 
Git
 
Branch Management
 
Version Control
 
Share via

Master Git branch management with essential commands for creating, switching, merging, and deleting branches efficiently.

On this page
  • List Branches
  • Create a New Branch
  • Switch to a Branch
  • Create and Switch to a New Branch
  • Rename a Branch
  • Delete a Branch
  • Delete a Remote Branch
  • Merge a Branch
  • Rebase a Branch
  • List Remote Branches
  • Track Remote Branch

Git Branch Management Commands  

Effective branch management is crucial for a smooth development workflow. Here are essential commands for managing Git branches:

List Branches  

git branch

Lists all local branches in your repository.

Create a New Branch  

git branch branch-name

Creates a new branch for developing features or fixes.

Switch to a Branch  

git checkout branch-name

Switches to the specified branch.

Create and Switch to a New Branch  

git checkout -b branch-name

Creates a new branch and switches to it immediately.

Rename a Branch  

git branch -m old-name new-name

Renames a branch, allowing you to update the branch name without affecting the history.

Delete a Branch  

git branch -d branch-name

Deletes a branch that is no longer needed.

Delete a Remote Branch  

git push origin --delete branch-name

Deletes a branch on the remote repository.

Merge a Branch  

git checkout main
git merge branch-name

Merges the specified branch into the current branch.

Rebase a Branch  

git checkout branch-name
git rebase main

Rebases the current branch onto the main branch, creating a linear project history.

List Remote Branches  

git branch -r

Lists remote branches, showing branches that exist on the remote repository.

Track Remote Branch  

git checkout -t origin/branch-name

Creates a local branch tracking a remote branch, synchronizing your local branch with the remote.

 Advanced Git Commands for Pro Developers
Git Commands for Handling Merge Conflicts 
On this page:
  • List Branches
  • Create a New Branch
  • Switch to a Branch
  • Create and Switch to a New Branch
  • Rename a Branch
  • Delete a Branch
  • Delete a Remote Branch
  • Merge a Branch
  • Rebase a Branch
  • List Remote Branches
  • Track Remote Branch
Copyright © 2024 WE CODE NOW All rights reserved.
WE CODE NOW
Link copied to clipboard
WE CODE NOW
Code copied to clipboard