본문 바로가기

Code snippet

How to change git branch name and push to remote git repository

How to change git branch name and push to remote git repository

#git 브랜치 이름 변경 방법

 

Description:

There is a "branch_a".

You want to change the name to "branch_b" and push it to remote git repository

 

step #0: open your command terminal and go to your code folder

( "git" must be installed )

 

step #1: checkout to main branch

git checkout main

 

 

step #2: Verify current branches

git branch

 

 

step #3 : change local(in your computer) branch name

git branch -m  current_branch_name new_branch_name

e.g) git branch -m branch_a branch_b

 

 

step #4 : Check branch name change

git branch

 

 

step #5: remove previous branch

git push origin :current_branch

e.g) git push origin :branch_a

note) watch out ":"

 

 

step #6:upload new branch to remote git repository

git push --set-upstream origin new_branch

e.g) git push --set-upstream origin branch_b