1

could somebody explain me (or lead me to a good reference) the following issue?

I know that below is the correct push command that I have to use:

git push origin refs/heads/master:refs/heads/master

   (I also know that it has short forms, like:
        git push origin master:master
        or
        git push origin master)

However, once time, I did 2 following push (by mistake):

  (1) git push origin refs/heads/master:refs/remotes/heads/master

  (2) git push origin refs/heads/master:refs/remotes/origin/master

git report no error in both commands, although in (1), I have no remote name "heads".

  • My first question is: what does git push to the remote repository in these cases? Do they harm my remote repository?

  • The second question is: according to http://progit.org/book/ch9-3.html everything under "refs/remotes" is remote references which are to know the last commit ID on the corresponding remote branch at the last server comminication. Is it just for that (e.g. only for information), does any git command use these references?

Update with my findings about the command (2)

I carefully verified again the behavior of the command (2) by:

  • backup the remote repository
  • do the (2)
  • compare the two repositories (the current one and the backup)

I found differences in the current one (the one effected by command (2))

  • in "objects" folder, there are 2 new files created: one is .pack file and the other is .idx file
  • in "refs" folder, a new refs was create "remotes/origins/master"

I noticed that the output of command (2) was

Counting objects: 842, done.
Compressing objects: 100% (337/337), done.
Writing objects: 100% (651/651), 336.30 KiB, done.
Total 651 (delta 243), reused 612 (delta 218)
To file:///data/resto/central-repo
 * [new branch]      master -> origin/master

Now I made another test:

  • Clone the remote repo into 2 local repos
  • In one local repo, I made change on a file, commit, push (git push origin master)
  • In the other local repo

    • I made change on a file, commit
    • Push with git push origin master:master

      I got an error message from git: "...! [rejected] master -> master (non-fast-forward)..." That what I expect

    • Then I made a push with command (2) and the result was what I mention ealier above.

So it's obviously the (2) is different from git push origin master.

What is the meaning of "refs" folder in the remote repository? The command (2) create a new "refs" in the remote repositoty, what does it refer to?

Bao Ho
  • 617
  • 8
  • 10

1 Answers1

1
  1. the (2) push is really similar to git push origin master. Not sure about (1) though.

  2. As explained in "Are there different meanings to the concept of 'tracking' in git?", the refs/remotes namespace if for tracking branches: ie representing "the state of the branch in the remote repository the last time that remote-tracking branch was updated".
    Those references are uses by git fetch in order to know what commits to fetch (compared to what you already have in your repo)
    See the blog post "git: fetch and merge, don’t pull" written by SO contributor Mark Longair for more.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks, regading to my first question, I found that the (2) does something differently and I updated my question with the findings about it. +1 for the reference about "remote tracking" – Bao Ho Feb 19 '12 at 06:35