jdlcgarcia
jdlcgarcia

Reputation: 183

git branch -D does not delete local branch

I've been facing some issues with GIT lately. In my work we have some branches for develop, QA and so... sometimes a branch gets contaminated so we have to reset it. We make it like this:

  1. We delete the local branch with git branch -D develop_branch
  2. We delete the remote branch via gitHub interface.
  3. We create a new local branch with git checkout -b develop_branch
  4. We pull the branch with git pull origin develop_branch

In this very moment, the old code comes to our new branch. It may take some time for git to delete the branch? There's a way to be sure that the branch is deleted?

Thank you!!

Upvotes: 0

Views: 482

Answers (2)

Tonio
Tonio

Reputation: 1546

Even though the remote branch is deleted, you still have a copy of it in your refs/remotes. Add --prune to git pull (or git fetch) to automatically delete local remote refs not present in the origin.

  1. git branch -D develop_branch
  2. git push origin :develop_branch (or delete remote branch via GitHub interface)
  3. git checkout -b develop_branch
  4. git pull --prune origin develop_branch

Upvotes: 3

Mauddev
Mauddev

Reputation: 361

Check if remote branch is deleted:

git branch -r 

will show all remote branches

You don't need to use github interface to delete a remote branch, instead do:

git push origin :develop_branch

(Note the colon : before local_branch_name)

And in addition: after you make a new local branch, push it like this to 'copy' it to remote:

git push --set-upstream origin newlocalbranch

Upvotes: 0

Related Questions