Gabriel Gabriel - 2 months ago 11
Git Question

Will 'git push origin <branch>' remove <branch> remotely after removing it locally?

I'm following the git-flow model and I have a doubt.

First, I add a new feature branch from 'develop':

# Checkout from develop branch
$ git checkout -b <branch>
# Push and track <branch>
$ git push --set-upstream origin <branch>


After the feature is finished, I follow Incorporating a finished feature on develop:

# Switch to 'develop'
$ git checkout develop
# Merge <branch> into 'develop'
$ git merge --no-ff <branch>
# Remove <branch> locally
$ git branch -d <branch>
# Remove <branch> remotely <-- ???
$ git push origin develop


The last command is the one that I'm not sure about. Will it remove remotely the
<branch>
I just removed locally?

Answer

No; <branch> is only removed locally by virtue of git branch -d <branch>, but a copy of it exists on remote (if it was pushed there prior). This can be verified by running git branch -vvvv, which will show the remote branch with no associated local tracking branch.

git push origin develop will only push develop to your remote repository (origin) without touching anything else (barring any commit hooks). If <branch> did exist remotely and you wanted to delete it, you would have to add the deletion operation as a separate step (git push origin :<branch>).

Comments