Horje
How to Rename Branch in Git?

Renaming branches in Git is important for keeping your repository organized and understandable, especially when collaborating with others. Clear and descriptive branch names improve project management and help team members identify the purpose of each branch. Renaming branches also ensures consistency and clarity throughout the development process.

Approach 1: Using the ‘git branch -m’ command.

Step 1: Open your terminal or command prompt.

Screenshot-2024-05-04-013556

VS code terminal

Step 2: Navigate to the repository directory using the `cd` command.

cd <-directory->

Step 3: Initialize git, add commit, add files and create branch.

git init
git add -all
git commit -m 'first commit'
git branch -m <brach_name>
git branch

Screenshot-2024-05-04-014340

Step 4: Now run the following command to rename branch.

git branch -m <-old_branch_name-> <-new_branch_name->

and verify it using git branch

Screenshot-2024-05-04-014643

Approach 2: Using ‘git checkout’ command

Step 1: Open your terminal or command prompt.

Screenshot-2024-05-04-013556

Step 2: Navigate to the repository directory using the `cd` command.

cd <-directory->

Step 3: Initialize git, add commit, add files and create branch.

git init
git add -all
git commit -m 'first commit'
git branch -m <brach_name>
git branch

Screenshot-2024-05-04-014340

Step 4: Run `git checkout “<-old_branch_name->”` followed by `git branch -m “<-new_branch_name->”.

git checkout "<-old_branch_name->"
git branch -m "<-new_branch_name->

Screenshot-2024-05-04-015341




Reffered: https://www.geeksforgeeks.org


Git

Related
How to Add Upstream in Git? How to Add Upstream in Git?
How to Add Empty Folder in Git? How to Add Empty Folder in Git?
How to Add Submodule in Git? How to Add Submodule in Git?
.gitattributes vs .gitignore in Git .gitattributes vs .gitignore in Git
How to Merge Two Branches in Git? How to Merge Two Branches in Git?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
16