Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename remote branch

Tags:

git

I have created a local branch X that at some point I pushed to remote server (origin)

git push origin X

I realized it's a bad idea to have branch named X and want it to be called Y The problem is that I've already pushed the branch to the repository.

Is it safe to delete it from the server and push it under a new name like this ?

push origin :X

// 'clone ' the branch under a new name locally ( X-> Y)

push origin Y

What will happen to the people that already fetched from the server. Say that they already made a branch locally based on the old X name BUT they did not make any changes locally or pushed them to the server for the old X branch.

like image 700
Ghita Avatar asked Oct 20 '10 20:10

Ghita


People also ask

Can you rename remote branch?

To be precise, renaming a remote branch is not direct – you have to delete the old remote branch name and then push a new branch name to the repo. Step 2: Reset the upstream branch to the name of your new local branch by running git push origin -u new-branch-name .

How do I rename a remote master branch?

Rename your remote branchFrom the branches page of your repository, you can rename the branch by clicking the little pencil icon. GitHub will automatically update open Pull Requests.

How do I rename a remote in GitHub?

Renaming a remote repositoryUse the git remote rename command to rename an existing remote. The git remote rename command takes two arguments: An existing remote name, for example, origin. A new name for the remote, for example, destination.


1 Answers

other people will keep a pointer to branch X (as origin/X) in their repository until they run git remote prune origin. it's left as a stale branch

when fetching/pulling they will get a second point to (newly created) branch Y (as origin/Y)

branching and merging is not affected by this.

so, as long as all commits are still reachable from your branch, renaming is fine.

like image 66
knittl Avatar answered Oct 25 '22 02:10

knittl