0

Let us suppose I have developed a cool feature and pushed the branch my-cool-feature. I am sure all is ok and I do not need it anymore locally, because the branch will be merged into master.

Using git branch -d my-cool-feature throws some error message If you are sure you want to delete it, run 'git branch -D my-cool-feature'.

Would the use of the "-D" flag delete the branch remotely too or only locally?

Razvan Zamfir
  • 4,209
  • 6
  • 38
  • 252
  • Does this answer your question? [How do I delete a Git branch locally and remotely?](https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-locally-and-remotely) – phd May 04 '20 at 17:36
  • https://stackoverflow.com/search?q=%5Bgit%5D+delete+branch+locally+remote – phd May 04 '20 at 17:36
  • Except for `git fetch`, which calls up another Git to *get* stuff from them, and `git push`, which calls up another Git to *give* stuff to them and/or make changes to their branch and tag names and such, *everything* you do in Git works locally. (Remember that `git pull` means *run `git fetch`, then run a second Git command.* The fetch uses another Git; the second command works locally.) – torek May 04 '20 at 18:17
  • Your local Git holds *your* branches. The other Git you fetch from (with `git pull`) or send stuff to (`git push`) has *its* branches. Their branches aren't yours, nor vice versa. You just like to *sync* with them now and then. – torek May 04 '20 at 18:18

2 Answers2

1

Command git branch -D branch-name will delete branch only locally

Razvan Zamfir
  • 4,209
  • 6
  • 38
  • 252
Loppik
  • 328
  • 2
  • 8
1

git branch -D <branch-name> only deletes local branch.

To delete a branch from remote, there is a different command.

git push origin --delete <branch-name>

follow this link. https://www.git-tower.com/learn/git/faq/delete-remote-branch

Razvan Zamfir
  • 4,209
  • 6
  • 38
  • 252
Vishal
  • 113
  • 2
  • 14
  • What if I later I change my mind and want to pull it from remote? How do I do that? Using `git fetch --all` does not seem to work. – Razvan Zamfir May 04 '20 at 17:36
  • If you have not deleted the branch from remote , then just simply do `git checkout -b ` it should restore that branch – Vishal May 04 '20 at 17:39
  • If I `git checkout -b ` I get a `There is no tracking information for the current branch` message. – Razvan Zamfir May 04 '20 at 17:44
  • check if that branch exist on remote. Switch to master branch and try checkout. – Vishal May 04 '20 at 17:48
  • If you have branch remotly and don't have locally, you can invoke git pull --all, so you get all branches and just can git ch branch-name – Loppik May 04 '20 at 17:50
  • I always prefer `git fetch origin` rather than `git pull --all` for these kind of issues, as "fetch" only downloads data from a remote repository and does not try to integrate it on your files. – nandilov May 05 '20 at 00:48