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?
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.
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.
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 .
Resolved by renaming the branch and then deleting it.
branch -m origin/foo bad_foo branch -d bad_foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With