1

I know the command git push -d <remote> <branch_name>

I want to delete remote branch only from my local git env. The command above removes remote branch from my local and remote github also.

However, if I had removed remote branch in github directly like this,

enter image description here

there is no branch named feature/search in remote anymore, the command fails.

So, how can I remove remote branch in my local without interacting remote github?

Jeong Ho Nam
  • 803
  • 12
  • 20
  • https://stackoverflow.com/search?q=%5Bgit%5D+remove+remote-tracking+branch – phd Jul 29 '20 at 07:24
  • 4
    `git branch -d -r` to delete a local remote-tracking branch. – phd Jul 29 '20 at 07:25
  • ^----- this. Also one needs to give fuller name to the "local" version of the remote branch. Using the OP's branch one would need `git branch -d -r origin/feature/search` – colm.anseo Apr 19 '21 at 16:04

1 Answers1

2

Previously answered here.


You can use git branch -D or git branch -d for deleting a branch locally.

from the official doc

  -d
  --delete
  Delete a branch. The branch must be fully merged in its upstream branch, or in HEAD if 
  no upstream was set with --track or --set-upstream-to.

  -D
  Shortcut for --delete --force.

In your case, it should be,

  git branch -d feature/search
parthibx24
  • 61
  • 1
  • 4
  • The linked answer works. The 2nd half of this answer does not address the OP's issue - as the operation checked the remote git repo and fails once it discovers the remote branch no longer exists (stopping and not cleaning up the "local" tracking of the remote branch) – colm.anseo Apr 19 '21 at 16:02