Question

How can I compare a local branch against its remote upstream when I don't want to keep in mind what remote branch is its upstream?

In other words, I want to drop origin/bar in the second line below:

git branch --set-upstream master origin/bar
git log origin/bar..
Was it helpful?

Solution

origin/bar is just a convenient reference to the top revision of that branch in history that gets updated when you fetch changes from upstream.

If you do care about complete content of that branch, something somewhere would have to have a reference to it (or else it would eventually be garbage collected) and you would have to figure out the hash of revision at the top of that branch.

If you don't care about updated changes, then you can use git tag to mark top of the upstream branch at some point and then use the tag to diff the changes. Or you can create local branch off the top of origin/bar and use the local branch to diff against. Or you can just use git hash of topmost revision origin/bar.

Or you can put a symlink refs/remotes/origin/bar -> .git/refs/foo and then do diffs against foo. That would actually point to up-to-date origin/bar without being called origin/...

I'm not quite sure, though, why would you want to do that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top