8

Following the advice of a friend of mine, I started learning git. I read manual (basic sections) and I think understood most regarding commits, branches, setting backward, forward, etc. but when it comes to sync local repository with remote one, I feel slightly lost.

I am currently testing git on my `testrepository. I was adding files and folders locally, then updating a repository using website by adding additional files. Then I fetched files, merged commits and eventually I synchronised remote and local repositories. Now, I have got this log:

*   5cf86124752ed91bde703bca0133b904b356c430 (HEAD -> master, origin/master, origin/HEAD) Merge branch 'master' into HEAD
|\
| * 510cb404d9a7d062739da7960546187436941e8e Add folder_local1/{folde_local1_program1, folde_local1_program2, folde_local1_program3}
* | d7461473939ee6663535650fec08962b30865c6e Delete folder_server2_program4.java
* | 010aba572c7424e81446e151433805ec6d2d92ea Delete folder_server2_program3.java
* | a30e5a06923935edbcb362afb6cf5dc169ec5a61 Delete folder_server2_program2.java
* | 89dc387d36a0370844bf90bc028e9b335de2b0b5 Delete folder_server2_program1.java
* | f80348f8fa02960cd20f349a862b7a31700a0fdd Delete x
* | 12deed224204c2ef5ab60c92f39682628fb23ab1 Add files via upload
* | f00f6b3d4feecd00f1258f32456e4bb5e2b4af4b Create x
* | 0e7965394aa9d36a17fefb2b52c032627c1e8e28 Add files via upload
* | 7d594dcdcd4b169a0563f63070c8975a5ee1bc27 Add files via upload
* | c078101bae4a3413700242025f2db9c4aeb9b1d8 Add files via upload
* | 9dab1a30425e4fc57e57770deb475dea341ab136 Update folder_server1_program1.java
* | 41b6ecad4759fdadcda8955046582178693612ae Create folder_server1_program1.java
|/
*   be40ad56685d5f836b88de960feb2d7b881e6f93 Merge branch 'master' of github.com:FranekW/testrepository
|\
| * 2790ba683034812c83da1310993e6326f91da42d Create README.md
* | 9caf9163056ccfc0b06cdd28704dee912f1643b5 Add folder1/{folder1_program1, folder1_program2, folder1_program3}
|/
* 376fe054b95134d7953cfafe3b70931ff036fbb8 Initial commit

Firs of all, origin/master and origin/HEAD are both in red. Second, I don't understand what is origin/HEAD doing there? I though HEAD is a pointer that points at my current commit. Could someone explain if the log is ok or I messed up too much. And also how to understand `origin/HEAD.

Many thanks

18

HEAD has a few additional uses.

Due to HEAD being a pointer to the "current" commit, it is also the commit you get by default when cloning that repository. So in remote repositories, even though they don't have a worktree, HEAD can still exist as a pointer to the "default" branch – the one that clones will check out automatically.

(For example, some projects point HEAD of the "master" repo to a 'dev' or 'stable' branch instead of master, so that people get something more useful by default.)


In your case however, after cloning, Git keeps the <remote>/HEAD ref around because it has yet another use: it defines the branch Git tools will try if only the remote name is specified.

For example, normally you couldn't do git log origin, since refs/remotes/origin/ is a directory, thus cannot point anywhere. However, Git then automatically looks for origin/HEAD and gives you whatever branch that points to.

(This is settable using git remote set-head origin ... to whatever branch you find convenient.)

  • Hi. It makes a little bit more sense to me now but I am afraid I need more reading about remote branches, distributed git and git internals. Thanks – Celdor Mar 28 '17 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.