Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
773 views
in Technique[技术] by (71.8m points)

git fetch origin --prune doesn't delete local branches?

At one point I thought that git fetch origin --prune deleted local branches that were no longer present on the server. Somehow this is not my experience at the moment.

I ran this command, and the local branch was not deleted. It is not currently checked out. I ran git branch -vv to check this info, and I see

feature/MyGreatFeature           f30efc7 [origin/feature/MyGreatFeature: gone]

So it seems to know that it is gone. Why would it not delete my local branch?

Running git version 2.7.4 (Apple Git-66)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The various prune options (git remote update --prune, git remote prune, git fetch --prune) only delete remote-tracking branches.1

You'll need to manually delete local branches you no longer want, or change or remove their upstream setting if the remote-tracking branch no longer exists. Note that each local branch can record a remote and/or branch that do not now, or even never did, exist. In this case Git mostly acts as if those local branches have no upstream set, except that since version 1.8.5, several commands report the upstream as "gone" or otherwise invalid, and may suggest using --unset-upstream.


1More precisely, they delete destination refs after doing the refspec mapping from the command line or fetch lines from the configuration. Hence, for fetch mirrors, they can delete local branches. Most clones are not set up as fetch mirrors, though.

There were some recent bug fixes for complex mappings, to make sure that Git did not prune a mapped branch in some cases when it should not. For any normal repository—ordinary clone or pure fetch mirror—these fixes have no effect; they matter only if you have complicated fetch configurations.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...