0

Basically I'm used to git fetch an then : git diff remotes/origin/my_branch_to_compare_with

But now I did a git fetch and then git diff remotes/origin/the_remote_branch_I_want_to_compare_with : git is still showing some diffs... How is that possible ? I guess it store information about the remotely deleted branch ? The remote branch was deleted from gitlab.

St3an
  • 726
  • 1
  • 6
  • 21
  • I apologize if this sounds rude; it's not meant to be. The basic problem is that you don't know what these git commands do. I suggest that you read up on the git documentation so you will know what `git fetch` actually does, as well as `git diff`. Then you will know what is going wrong with your repo right now, and you will have a better grasp of what to do with your repo in the future. Peace and luck. – SaganRitual Mar 09 '18 at 10:31
  • Also have a look [**here**](https://stackoverflow.com/questions/292357/what-is-the-difference-between-git-pull-and-git-fetch) to get some insight into the subtleties of `git fetch`. – SaganRitual Mar 09 '18 at 10:33
  • @GreatBigBore - As someone with a pretty solid understanding of git, I can tell you that what you wrote DOES sound rude, because it IS rude. You are assuming the poster doesn't know what those commands do, but you have no actual reason to think that. Nothing in the question shows such lack of knowledge. And while the question could be stated more clearly, it has a perfectly straightforward answer. – Mark Adelsberger Mar 09 '18 at 14:33
  • @MarkAdelsberger He did a `git diff` against a branch he said had been deleted, and he did a `git diff origin mybranch`, which is an error, and he doesn't know why. However, I apologize if my conclusions about OP's knowledge differ from yours, as well as my judgments about rudeness. I meant you no offense either. I wish you peace and luck. And upvotes on your helpful answer. Actually, I'll start the process myself. Your answer and his research into `git diff` and `git fetch` will all benefit him significantly. Be well. – SaganRitual Mar 09 '18 at 14:54
  • @GreatBigBore - So having been called out on condescending to OP, your response is to not only continue doing so but to condescend to me as well? FWIW, no he didn't do "a `git diff` against a branch he said had been deleted", nor did he show a command where he `diff`d against any branch. That distinction is key to the question and shows where both you AND he didn't have full knowledge - so again, claiming he doesn't know what fetch and diff do was entirely uncalled-for. It's not about differing conclusions; it's about you wanting to get by with rudeness by covering it with smarm. – Mark Adelsberger Mar 09 '18 at 15:14
  • @MarkAdelsberger I surmise that we simply have different sensibilities about rudeness. For example, I'm not offended at all by your statement that I don't have full knowledge. You're right, I don't. Further, if you don't see `git diff origin mybranch` in his post, then we have other differences. I don't understand why you would focus on my "rudeness", rather than seeing that I offered him suggestions that he will indeed benefit from. As for your assumption that you know what's going on in my mind, I guess we differ there too. I genuinely wish you peace and luck. – SaganRitual Mar 09 '18 at 15:25
  • @MarkAdelsberger Let's not forget that we are, differences or no, brothers. – SaganRitual Mar 09 '18 at 15:27

1 Answers1

2

If there is a branch on the remote, and you clone the remote and locally check out the branch, there are now (at least) three refs related to the branch.

1) The branch in the remote

2) The branch in the local repo

3) A "remote tracking ref" in the local repo; sometimes called a "remote tracking branch", but be aware it is not a branch

As you may know, the remote tracking ref is updated when you fetch so that the local ref

origin/some-branch

tells you where the remote repo's branch

some-branch

pointed as of that fetch. What you may not know is that by default, when a branch is deleted from the remote, fetching does not automatically delete the corresponding remote tracking ref.

If you want the local to delete the remote tracking ref, you can say

git fetch --prune

But until you either do that, or manually delete the remote tracking ref from the local repo, the local will remember where the remote's branch pointed the last time a fetch reported that the branch existed.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52