Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I accidentally created a local branch named origin/foo. Now what?

Tags:

git

branch

I have a remote branch named foo, that is not tracked in the current client.

I did git checkout -b origin/foo, and this created a local branch named origin/foo. This looks bad, since up until now all my local branches didn't have a origin/ prefix.

I tried to delete this local branch by running git branch -d origin/foo, but it complained that the branch is not fully merged. I'm afraid that if I'll force it using -D, it will actually delete the remote branch.

How do I clean up this mess?

like image 329
ripper234 Avatar asked Dec 28 '11 08:12

ripper234


People also ask

How do you delete a accidentally created branch in git?

To delete a local Git branch using the terminal, run the following: git branch -d <branch name> . Keep in mind, if you're using a terminal other than GitKraken Client, you won't have immediate visual confirmation that the Git branch has been properly deleted from your repository.

How do I delete a local origin branch?

Deleting a branch LOCALLY Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet. The branch is now deleted locally.

How do I delete a remote origin branch?

To delete a remote branch, you can't use the git branch command. Instead, use the git push command with --delete flag, followed by the name of the branch you want to delete. You also need to specify the remote name ( origin in this case) after git push .


1 Answers

Resolved by renaming the branch and then deleting it.

branch -m origin/foo bad_foo branch -d bad_foo 
like image 161
ripper234 Avatar answered Sep 22 '22 17:09

ripper234