46

I am using git along with git flow. Here git flow has a develop branch. Whenever i need to start feature i type

git flow feature start new

a new branch feature/new is created. Then i do the changes and commit them using

git push origin feature/new

After comitting the changes I finish feature using

git flow feature finish new

it deletes feature/new branch locally. Now I am switched to develop branch by git flow and I again type

git push origin develop

which make changes to remote server develop branch

If I type git branch -a, the new branch got deleted from the local but it is there on the server with name remotes/origin/feature/new

Does git flow delete branches on remote server which are deleted at my local machine?

Please tell me if I am making some mistake.

Stefan
  • 109,145
  • 14
  • 143
  • 218
Paritosh Singh
  • 6,288
  • 5
  • 37
  • 56

3 Answers3

43

Looking at the source it seems that the remote feature branch is deleted only if you call git flow feature finish with -F.

However, this fetches the remote before finishing the feature. From the docs:

-F fetch from $ORIGIN before performing finish

Otherwise you can delete the remote branch manually with:

git push origin :feature/new
Natan R.
  • 5,141
  • 1
  • 31
  • 48
Stefan
  • 109,145
  • 14
  • 143
  • 218
  • Also note that if you never pushed that branch upstream to a remote server like 'git push --set-upstream origin branch', when calling 'git flow feature finish' you will never have the remote branch. – Nick N Jul 14 '18 at 15:07
30

May I suggest using the git-flow AVH Edition.

Like Stefan said, the original version only deletes the remote branch when you use -F, which is kinda strange. The AVH Edition fixes this quirky behavior, it will always delete the local and remote feature branch on a finish, unless you specify either

  • --keep, which keeps the local and remote.
  • --keeplocal, which keeps the local, but deletes the remote.
  • --keepremote, which keeps the remote, but deletes the local.

You can find git-flow AVH Edition on github.

Dave Reece
  • 35
  • 8
Peter van der Does
  • 14,018
  • 4
  • 38
  • 42
  • Does AVH Edition handle ```feature pull``` better too? I just set a bounty, because the ```feature pull``` in original git-flow is very confusing (http://stackoverflow.com/questions/18412750/why-doesnt-git-flow-feature-pull-track), appreciate any input to have a cannonical answer. – dashesy Jan 04 '14 at 19:46
  • The feature pull command will be deprecated per version 2.0 and only feature track will be available. – Peter van der Does Mar 03 '14 at 15:00
  • Is there a way to automatically tag where the feature branches HEAD was before it removes it? I like to see the little green tags in git-web, but when the remote is deleted, those go away. – avatarofhope2 Jan 19 '18 at 19:41
  • Note: git-flow AVH edition is the default in Git for Windows. You can confirm this by running `git flow version`. – geekley Sep 25 '18 at 17:25
  • 1
    Also, you can change the default behavior with, for example, `git config gitflow.feature.finish.keepremote true`. – geekley Sep 25 '18 at 17:26
7

What I had to do:

git flow feature delete -f name_feature

The -f is necessary if there are changes inside the feature branch.

git push origin --delete feature/name_feature

That is to delete the remote branch as well.

David Prieto
  • 2,239
  • 4
  • 32
  • 51