Shell/Bash: rename branch git Example


Shell/Bash Example: This is the "rename branch git" Example. compiled from many sources on the internet by

git rename branch

git branch -m   # Any Branch
git branch -m  # Current Branch

# For windows if you get "Branch already exists" error
git branch -M 

how to rename git branch fro master to main

# Step 1 
# create main branch locally, taking the history from master
git branch -m master main

# Step 2 
# push the new local main branch to the remote repo (GitHub) 
git push -u origin main

# Step 3
# switch the current HEAD to the main branch
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

# Step 4
# change the default branch on GitHub to main

# Step 5
# delete the master branch on the remote
git push origin --delete master

rename branch git

git branch -m 

git rename local branch

git branch -m  

edit branch name git

$ git checkout Branch-Name-You-Want-to-Change
$ git branch -m New-Branch-Name

rename branch git

git branch -m  //currenct branch switch name 
git branch -m  

* Summary: This "rename branch git" Shell/Bash Example is compiled from the internet. If you have any questions, please leave a comment. Thank you!