tags:

views:

70

answers:

2

So imagine that I have a local repository that I've cloned from some origin. At the time of my intial clone, the origin had four branches: featureA, featureB, featureC and master. If I push changes to the origin that delete the featureA branch I'd expect to see something about it being deleted the next time I issue:

$ git pull origin

However, what happens is that I don't see anything and when I try to pull that specific branch down with

$ git pull origin featureA

I get the following error:

fatal: Couldn't find remote ref featureA
fatal: The remote end hung up unexpectedly

This totally makes sense, as the branch was in fact deleted from the remote so yeah, the ref is not there anymore however I'm wondering why I didn't get notified about this fact. My .git/config for the remote looks like this:

[remote "origin"]
fetch = +refs/heads/:refs/remotes/origin/
url = [email protected]:/data/git/perecep.git

I've written a small shell script that uses the git ls-remote along with the output from git branch -r to detect remote refs whose branches no longer exists on the server and prompt me if I would like to delete them but I'm wondering if I'm just doing something inherently wrong here?

+2  A: 

I don't think you're doing anything wrong. Your local branch does not depend on the remote branch for existence, and it is a perfectly valid state of affairs for a remote branch to be deleted while your local branch (of the same name and ostensibly the same history) to go on existing. It's the "centralized" approach you are describing, if anything, that would be considered unorthodox in Git.

Edit: Tangentially, you may be interested in the --track and --no-track options to git-branch, and the branch.autosetupmerge config variable.

ezod
I am following a more "central server" workflow with Git b/c I am in a corporate environment and this is how developers with laptops would prefer to share code (by creating public topic branches on a central server to push their changes to for collaboration) for now. Since we are newly transitioned from SVN this is something that they are more comfortable with.I guess my concern is that after creating several ephemeral branches of this nature that get deleted after the feature/topic gets integrated, all the developers now have tons of stale remote branch refs in their local repo.
NewGitUser
+2  A: 

Okay, no need for a special script. I guess I overlooked this command

$ git remote prune origin

From the man page:

  prune
           Deletes all stale tracking branches under . These stale branches 
           have already been removed from the remote repository referenced by 
           , but are still locally available in "remotes/".

           With --dry-run option, report what branches will be pruned, but do 
           no(sic) actually prune them.
omnisis
@omnisis is there any setting that does this auto-magically when you update the remote?
xenoterracide