Snedden27 Snedden27 - 2 months ago 8
Git Question

Need help interpreting git log --graph command

So, I am a little confused on how

git log --graph
works.

Here is my repository on GitHub: https://github.com/Snedden/capstone

I haven't created any branches apart from the
master
branch.

But when I run the command
git log --graph
(on my local repository) it appears I had a branch around the commit "standardised urls for better portability"

git log output

So my question is, if that's not a separate branch then why does it appear to be like a separate branch in the
git log
output?

NOTE: Some info, when I tried pushing on c228400 git said I had to pull first as it thought my remote is ahead of my local, I am not sure how this is possible as I always did linear pushed some the same account.


Answer

The answer is in your graph (which is an image, so I've transcribed it here, more or less):

*  44ccab (HEAD -> testBranch, origin/master, origin/HEAD, master)
|    Merge branch 'master' of https://github.com/Snedden/capstone
|\
| * c228400 standardised urls for better portability
* | 90bbf9e added stage axis and d3 library
* | 2d0ce65 standardised urls for better portability
|/
* 4c?02a4 datasets implemented

You did, in fact, merge two branches.

The two branches you merged were master and master.

One of these two masters is your master. The other is 'master' of <another repository>.

This is the kind of merge that git pull makes. Remember, git pull means "Run git fetch, then run git merge unless I tell you in advance to run git rebase instead of merging."

The message that git pull sets for the merge is Merge branch 'name' of URL. The name part comes from the branch you tell your Git to use. The contents of that branch are whatever your Git retrieves from the given URL after those contents are brought into your repository (under some other name, since obviously master is already in use!).

That is, you merged in someone else's master. Now, that "someone else" is probably you, but Git doesn't know or care, it just knows the URL.

If you run git fetch instead of git pull, you can choose whether to run git merge or git rebase after you've done the fetch, instead of deciding before, sight-unseen. Moreover, if you then choose to merge, you'll merge by the name you are using in your repository, i.e., origin/master, rather than by the weird name master :-) that some other guy is using in that other repository over there on github.com. This may make more sense to you later (or maybe not).

Given that the commit messages of 2d0ce65 and c228400 are the same, I suspect you rebased or amended a commit after pushing c228400. This made a copy of the commit (an imperfect copy, on purpose, with something changed). You then added the "stage axis and d3 library" commit, and then when you ran git pull, your Git dutifully merged your two commits, 2d0ce65 plus 90bbf9e, with the other guy's one commit, c228400, found on github.

Those were your two branches: your branch master, and that other you's master over on GitHub.