1

I have created a Git repository locally and committed a file to it:

$ mkdir blarg && cd blarg

$ git init
Initialized empty Git repository in /home/myuser/tests/blarg/.git/

$ echo a line > test.txt

$ git add .

$ git commit -m "initial commit"
[master (root-commit) f47ef6d] initial commit
1 file changed, 1 insertion(+)
create mode 100644 test.txt

I want my server to host this repository, so I have created a bare empty repository there and configured access to it (this part works fine). I can set this repository as a remote in my local repo and push to it:

$ git remote add --track master origin https://git.example.net/repos/blarg.git

$ git remote -v
origin  https://git.example.net/repos/blarg.git (fetch)
origin  https://git.example.net/repos/blarg.git (push)

$ git push origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 216 bytes | 216.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://git.example.net/repos/blarg.git
* [new branch]      master -> master

$ git pull
Already up to date.

$ git status
On branch master
nothing to commit, working tree clean

$ git log --oneline
f47ef6d (HEAD -> master, origin/master) initial commit

This all seems to work as intended. However, after cloning this repository from the server into a new directory, the git status message is slightly different in the cloned repo, and git log also shows one more ref than in the original repo:

$ cd ..

$ git clone https://git.example.net/repos/blarg.git blarg2
Cloning into 'blarg2'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done

$ cd blarg2

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

$ git log --oneline
f47ef6d (HEAD -> master, origin/master, origin/HEAD) initial commit

Note that git only prints "Your branch is up to date with 'origin/master'." in the cloned repository, and that the log there mentions origin/HEAD.

What's going on, and how can I adjust my original repo to behave like the cloned one?

  • 1
    This might be useful: https://superuser.com/questions/1192865/git-what-does-an-extra-item-origin-head-mean – bromps Jul 27 '19 at 17:52

1 Answers1

1

Your branch is up to date with 'origin/master'

This means that the branch has been setup to track the master branch on origin. You can set this up on your original local repo like this:

git branch --set-upstream-to=origin/master

See this.

f47ef6d (HEAD -> master, origin/master, origin/HEAD) initial commit

origin/HEAD is pointing to the tip of master here because the local repo is using master as the default as the branch for origin i.e. the branch that will be used by commands like git log origin with no branch specified.

You can set this up on you original repo like this:

git remote set-head origin master

See this, as mentioned by daChihan.

Calum Halpin
  • 1,470
  • 1
  • 8
  • 15