2

I work on a project with others developers, with a Github repo. We made a branch, then after the work with it has finished, we deleted the branch on Github. But on my local repo, I have again the branch (I see it on calling git branch --list -a). It was a remote branch, but it doesn't exist anymore on the remote repo.

I tried with git branch -d remotes/origin/<branch> (also with -D but that is not the problem). Git answered "error: branche 'remotes/origin/morgan-save-A' non trouvee" .

How could I delete it, if someone has an idea ? Thanks for reading :)

phd
  • 82,685
  • 13
  • 120
  • 165
  • 1
    To delete a remote-tracking name with `git branch`, you must include the `-r` option. Using `--prune` (or `-p`) with `git fetch`, or running `git remote prune`, is easier. Consider also or instead setting `fetch.prune` to `true`. – torek Mar 29 '21 at 11:05
  • https://stackoverflow.com/search?q=%5Bgit-branch%5D+delete+remote – phd Mar 29 '21 at 11:38
  • Thanks @torek and @KaspiR, I cannot vote for comments (due to my reputation, I think). `git fetch --prune origin` made the expected operation :) – morgan prieur Mar 29 '21 at 11:49

1 Answers1

2

What about git fetch --prune

From the docs:

Before fetching, remove any remote-tracking references that no longer exist on the remote. Tags are not subject to pruning if they are fetched only because of the default tag auto-following or due to a --tags option. However, if tags are fetched due to an explicit refspec (either on the command line or in the remote configuration, for example if the remote was cloned with the --mirror option), then they are also subject to pruning. Supplying --prune-tags is a shorthand for providing the tag refspec.

kapsiR
  • 2,720
  • 28
  • 36
  • Thanks for the tip, that will be helpful, but Git says `git fetch --prune remotes/origin/ fatal: 'remotes/origin/' does not appear to be a git repository fatal: Impossible de lire le dépot distant. Veuillez vérifier que vous avez les droits d'acces et que le dépot existe.` Perhaps I have to delete the reference (tracking) to the remote deleted repo ? – morgan prieur Mar 29 '21 at 11:13
  • 1
    You don't have to provide a branch name, it prunes all remote branches. e.g. `git fetch --prune origin` should do the trick for you – kapsiR Mar 29 '21 at 11:19