Git Flow : Do you have to manually delete the feature branches from remote after finishing the feature?

Yugal Jindle picture Yugal Jindle · Jun 22, 2012 · Viewed 8.4k times · Source

I am new to GIT and GIT-Flow. [ On my python-django project ]

What I did :

git flow feature start new_feature
# perform some commits on the feature/new_feature branch

git push origin feature/new_feature

git flow feature finish new_feature
# I suppose that merges feature/new_feature to develop and deletes feature/new_feature

git push origin develop # Pushes the new changes to remote

Problem:

  • The feature/new_feature branch seems to be deleted on my local machine.
  • But on github [ My remote named origin ] I can see the branch feature/new_feature.
  • I am confused, it shouldn't show deleted branches.
  • I looked around for solution - but they say you should delete them on remote manually, which doesn't seem to fit the abstraction of git flow

So, do you guys have to delete all your feature branches from all the remotes every time you use git-flow ??

Am I doing something wrong ?

Answer

VonC picture VonC · Jun 22, 2012

If you ever did a git push origin (with feature being checked out locally), know that the current default pushing policy is default.
That means (git config man page)

matching - push all branches having the same name in both ends.

But:

This is currently the default, but Git 2.0 will change the default to simple.

upstream - push the current branch to its upstream branch.
With this, git push will update the same remote ref as the one which is merged by git pull, making push and pull symmetrical.

(since feature has initially no upstream branch in GitHub, it wouldn't be pushed)

(That change of policy is in discussion for the past few months)

So for now, if you did push your feature branch to GitHub, before merging it locally to develop and pushing develop, you need to remove your feature branch from GitHub:

git push origin :feature

The only reason why git flow wouldn't remove a feature branch if you didn't specified a flag 'fetch' at any point during the process. See sources.

# delete branch
if flag fetch; then
  git push "$ORIGIN" ":refs/heads/$BRANCH"
fi

That means you should have done a

git flow feature finish -F new_feature

The idea is to fetch first and make sure there is no new evolution added to new_feature on GitHub by other contributors, before deleting it.