Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming branches remotely in Git

Tags:

git

branch

rename

If there is a repository that I only have git:// access to (and would usually just push+pull), is there a way to rename branches in that repository in the same way that I would do locally with git branch -m?

like image 418
kdt Avatar asked Jan 20 '11 23:01

kdt


People also ask

Can you rename branches in Git?

The git branch command lets you rename a branch. To rename a branch, run git branch -m <old> <new>. “old” is the name of the branch you want to rename and “new” is the new name for the branch.

How do I change a branch name in both remote and local?

Git Branch Rename Command The steps to change a git branch name are: Rename the Git branch locally with the git branch -m new-branch-name command. Push the new branch to your GitHub or GitLab repo. Delete the branch with the old name from your remote repo.

What is Git remote rename?

Now that the current remote name is confirmed — you can change it by running this command: git remote rename beanstalk origin. This command tells git to rename the current remote to something different. In this example, we're changing the remote name to “origin”, but you can change your remote to be anything you want.

How do I rename a remote Git repository?

Select the repo you want to rename under Git repositories on the left and select .... Select Rename repository... from the menu. If the Repositories pane is not expanded, select > to expand it and display the list of repositories. Enter a new repo name in the Repository name field in the dialog, then select Rename.


1 Answers

You just have to create a new local branch with the desired name, push it to your remote, and then delete the old remote branch:

$ git branch new-branch-name origin/old-branch-name $ git push origin --set-upstream new-branch-name $ git push origin :old-branch-name 

Then, to see the old branch name, each client of the repository would have to do:

$ git fetch origin $ git remote prune origin 

NOTE: If your old branch is your main branch, you should change your main branch settings. Otherwise, when you run $ git push origin :old-branch-name, you'll get the error "deletion of the current branch prohibited".

like image 50
Sylvain Defresne Avatar answered Oct 07 '22 06:10

Sylvain Defresne