0

I created a branch from master to work on a given feature.

git branch new_feature
git checkout new_feature

Then I finished the feature so I merged to master and deleted the branch:

git commit -m "Finished feature"
git push origin my_feature
git checkout master
git merge new_feature
git branch -d new_feature

Then I pushed to master:

git push origin master

The problem is that in the repository the branch new_feature still exists in the remote repo and I am not understanding why. How do I push an exact snapshot of my local repo to the remote repo?

jscherman
  • 5,389
  • 12
  • 42
  • 84

2 Answers2

1

If you want to delete the new_feature branch on the remote, then you need a separate Git command for that:

git push origin :new_feature

The Git documentation explains the syntax being used above:

Because the refspec is <src>:<dst>, by leaving off the <src> part, this basically says to make the topic branch on the remote nothing, which deletes it.

In other words, it is a bit like saying that nothing is linked to the remote branch, i.e. you are cutting it loose and deleting it.

Tim Biegeleisen
  • 451,927
  • 24
  • 239
  • 318
0

This is core concept of git - it is distributed version control system. So each working copy of repository lives with its own life, and could be synchronized with one, remote (origin) repository. Thus, you need to remove your branch from local and from remote repo.

git branch -d origin/new_feature

In order to avoid it, try to avoid pushing all your local branches to remote repositories. When you create feature branch, just consider how much time it'll take to finish it - maybe, it does not make sense to push it to remote, and work just locally?

kosist
  • 2,021
  • 2
  • 16
  • 28