How to rename a remote and same local branch from the remote?

Asked

Viewed 376 times

1

Which command should be used to rename a branch and update its name branch local?

2 answers

4


You can also do as follows:

$ git branch -m nome_antigo nome_novo         # Renomeia o *branch* local   
$ git push origin :nome_antigo                # Deleta o *branch* antigo no repositório remoto (dois pontos + nome do *branch*)    
$ git push --set-upstream origin nome_novo    # Push no novo *branch*
  • Great, I didn’t know the -m

2

The name of a branch in git is only a reference, what really counts is the sequence line between the commits along with their hashes.

So, all you have to do is create a new branch under the new name:

git checkout -b branch-renomeada

And then push that branch (assuming your remote repository is as origin):

git push origin branch-renomeada

After that, if you want you can delete the branch ancient:

git branch -D branch-antiga

To remove the branch remote with old name, if you have already pushed previously:

git push origin :branch-antiga

Browser other questions tagged

You are not signed in. Login or sign up in order to post.