10

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 ?

Yugal Jindle
  • 44,057
  • 43
  • 129
  • 197
  • haven't you pushed in between? unless there's no way the branch appears on origin – CharlesB Jun 22 '12 at 06:07
  • I pushed after I finished the feature, I suppose it should also delete the remote branches if I delete it on my local git and pushed. Why is this out-of-sync in git repos even after a push ? – Yugal Jindle Jun 22 '12 at 06:30

1 Answers1

6

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Sir, please see the edit to the question. I missed some info. – Yugal Jindle Jun 22 '12 at 07:16
  • @YugalJindle I just added a reference to git flow source. – VonC Jun 22 '12 at 07:23
  • I understand that sir, but then why doesn't it deletes the branch on the remote origin when I push after the deletion of the branch locally. As per present `push` policy - It should. Shouldn't it ? – Yugal Jindle Jun 22 '12 at 07:51
  • @YugalJindle your last push concerns only `develop`, not `new_feature`. If `new_feature` wasn't deleted on the remote by `git flow finish`, your push wouldn't change that. – VonC Jun 22 '12 at 07:56
  • @YugalJindle Isee in the source that the remote branch is only deleted if the flag 'fetch' has been defined. That happens only if you do a `git flow finish -F ...` (no `-F`, no fetch option, no remote deletion) – VonC Jun 22 '12 at 07:58
  • Is there a way so that I can reflect all local commits to remote, across branches? – Yugal Jindle Jun 22 '12 at 07:58
  • @YugalJindle I just edited my answer. The deletion would have been reflected with the `-F` option to `git flow finish`. Right now, I would recommend a manual fix (the `git push :new_feature`). – VonC Jun 22 '12 at 08:01