How To Rename Git Remote Branchs and Local Branches-DecodingDevOps
How To Rename Git Remote Branchs and Local Branches-DecodingDevOps
whatever the procedure we are using to rename the git branches, we use the same procedure for github or bitbucket or gitlab. in the following steps i will show you how to rename git remote branch and how to rename git local branch. so now you can use below commands in all cases like git bitbucket, gitlab.
Git Rename Local Branchs
If It Is A Current Branch:
If you want to change the current branch which you are in right now you, can use below command. This command will rename your current local branch but not remote branch.
git branch –m new_branch_name
If It Is Another Branch:
git branch -m old_branch_name new_branch_name
if you are in one branch and if you want to change another branch you can use above command. This command will change the branch name in locally not in remote.
Git Rename Remote Branch
Using the above commands, we have changed the branch name in local. So now we have to change this name in the remote.
for that, you need to follow three steps. with these three steps you can rename git remote branch.
- pull your changes
- delete the old branch in remote
- push your newly renamed branch and track that new branch with local
Before deleting your old branch in remote make sure that you have the latest version of the code in local from the remote. Or make sure that you are in sync with the remote branch for that you need to pull the changes. If you delete the old branch without pulling you may loose newly changes done by any developers. So first check out to your new named branch.
git checkout new_branch_name
Now pull your changes
git pull
Now you have all the files
Now you can delete the old branch from the remote.
Delete The Old Branch In Remote:
git push origin :old_branch_name
here you are deleting the old branch from the remote and no need to fear that you are deleting a branch since already you have that branch in locally with a different name. just you need to push our locally renamed new branch.
Push New Branch and Track With Remote
git push --set-upstream origin new_branch_name
it will push your newly renamed branch and all your files to remote. and both remote and local will be in track. now we have completed the git remote branch
now we have successfully renamed the git branch locally and remotely.
- git rename branch
- github rename local branch
- git rename remote branch name
- bitbucket rename branch name
- git rename a branch
- bitbucket rename remote branch name
- git rename remote branch without deleting
- rename remote branch gitlab
- git rename branch local and remote
- rename branch remote and local git
- how to rename branch name in git
- how to rename branch name in bitbucket