Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I deleted a branch in remote, how do I synchronize in local?

I created a repository on Github. I have two development environments, and I access Github with Github for Windows on both.

On one of the two development environments, I deleted a branch and clicked "synchronize" in Github for Windows. The branch appropriately got deleted in Github. When I synchronized from my other development environment, there was an option to "publish" the branch-to-be-deleted, but none to delete it.

How can I tell git or Github for Windows to make a full sync, including the deletion of obsolete branches?

like image 925
Olivier Grégoire Avatar asked Sep 11 '17 12:09

Olivier Grégoire


1 Answers

Yes and no — depending on what you really meant by "deletion of a local branch".

A quick answer

  • No, it's impossible to have a remote repository delete a normal branch in your local repository.

  • Yes, it's possible to ask Git delete remote branches in your local repository for the branches which were deleted on a particular named remote (such as "origin").

    This one is achieved by running

    git remote prune origin
    

    or

    git fetch --prune
    

Explanations

Please do understand first that Git's model with working with remote repositories is asymmetric: the fact a branch in your local repository has the name exactly matching that of a branch in a remote repository has no meaning to Git.

The reason is two-fold:

  • Your local repository is treated by Git as completely self-containing and not depending on any other repositories.
  • Your local repository is able to communicate with any number of remote repositories, and…
  • …those repositories may have absolutely no "conceptual" relation with your local repository: for instance it's possible to fetch the data from a repository hosting the Linux source code into a repository containing your weekend toy project.

So while Git has certain helpers to somewhat tie local branches to particular remote branches, these ties are asymmetric. In particular, Git treats your local history as being "sacred", and destructive operations on it require your explicit actions.

like image 77
kostix Avatar answered Sep 22 '22 14:09

kostix