How does origin/HEAD get set?












110















I have a branch set up to track a ref in origin. git checkout <branchname> switches to that branch, and a git status will show me how far ahead or behind my branch is from origin, but I'm surprised that origin/HEAD still points at origin/master, and not origin/<branchname>



So my question is, under what circumstances does origin/HEAD get moved?



EDIT:



I appreciate the answers about how to move origin/HEAD, but I'm interested in what "organically" moves it, outside of me explicitly telling it to do so.



For example, when I switch branches, git makes HEAD point at the branch I'm checking out, so I'm surprised that origin/HEAD doesn't move in the same manner.










share|improve this question

























  • Note that this question is about local symbolic references on remotes, like refs/origin/HEAD. It is not about how a repository's own symbolic reference HEAD gets set.

    – clacke
    Mar 28 '17 at 16:53
















110















I have a branch set up to track a ref in origin. git checkout <branchname> switches to that branch, and a git status will show me how far ahead or behind my branch is from origin, but I'm surprised that origin/HEAD still points at origin/master, and not origin/<branchname>



So my question is, under what circumstances does origin/HEAD get moved?



EDIT:



I appreciate the answers about how to move origin/HEAD, but I'm interested in what "organically" moves it, outside of me explicitly telling it to do so.



For example, when I switch branches, git makes HEAD point at the branch I'm checking out, so I'm surprised that origin/HEAD doesn't move in the same manner.










share|improve this question

























  • Note that this question is about local symbolic references on remotes, like refs/origin/HEAD. It is not about how a repository's own symbolic reference HEAD gets set.

    – clacke
    Mar 28 '17 at 16:53














110












110








110


60






I have a branch set up to track a ref in origin. git checkout <branchname> switches to that branch, and a git status will show me how far ahead or behind my branch is from origin, but I'm surprised that origin/HEAD still points at origin/master, and not origin/<branchname>



So my question is, under what circumstances does origin/HEAD get moved?



EDIT:



I appreciate the answers about how to move origin/HEAD, but I'm interested in what "organically" moves it, outside of me explicitly telling it to do so.



For example, when I switch branches, git makes HEAD point at the branch I'm checking out, so I'm surprised that origin/HEAD doesn't move in the same manner.










share|improve this question
















I have a branch set up to track a ref in origin. git checkout <branchname> switches to that branch, and a git status will show me how far ahead or behind my branch is from origin, but I'm surprised that origin/HEAD still points at origin/master, and not origin/<branchname>



So my question is, under what circumstances does origin/HEAD get moved?



EDIT:



I appreciate the answers about how to move origin/HEAD, but I'm interested in what "organically" moves it, outside of me explicitly telling it to do so.



For example, when I switch branches, git makes HEAD point at the branch I'm checking out, so I'm surprised that origin/HEAD doesn't move in the same manner.







git






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 12 '12 at 18:48







ecoffey

















asked Jan 12 '12 at 18:03









ecoffeyecoffey

1,44341622




1,44341622













  • Note that this question is about local symbolic references on remotes, like refs/origin/HEAD. It is not about how a repository's own symbolic reference HEAD gets set.

    – clacke
    Mar 28 '17 at 16:53



















  • Note that this question is about local symbolic references on remotes, like refs/origin/HEAD. It is not about how a repository's own symbolic reference HEAD gets set.

    – clacke
    Mar 28 '17 at 16:53

















Note that this question is about local symbolic references on remotes, like refs/origin/HEAD. It is not about how a repository's own symbolic reference HEAD gets set.

– clacke
Mar 28 '17 at 16:53





Note that this question is about local symbolic references on remotes, like refs/origin/HEAD. It is not about how a repository's own symbolic reference HEAD gets set.

– clacke
Mar 28 '17 at 16:53












5 Answers
5






active

oldest

votes


















141














Note first that your question shows a bit of misunderstanding. origin/HEAD represents the default branch on the remote, i.e. the HEAD that's in that remote repository you're calling origin. When you switch branches in your repo, you're not affecting that. The same is true for remote branches; you might have master and origin/master in your repo, where origin/master represents a local copy of the master branch in the remote repository.



origin's HEAD will only change if you or someone else actually changes it in the remote repository, which should basically never happen - you want the default branch a public repo to stay constant, on the stable branch (probably master). origin/HEAD is a local ref representing a local copy of the HEAD in the remote repository. (Its full name is refs/remotes/origin/HEAD.)



I think the above answers what you actually wanted to know, but to go ahead and answer the question you explicitly asked... origin/HEAD is set automatically when you clone a repository, and that's about it. Bizarrely, that it's not set by commands like git remote update - I believe the only way it will change is if you manually change it. (By change I mean point to a different branch; obviously the commit it points to changes if that branch changes, which might happen on fetch/pull/remote update.)





Edit: The problem discussed below was corrected in Git 1.8.4.3; see this update.





There is a tiny caveat, though. HEAD is a symbolic ref, pointing to a branch instead of directly to a commit, but the git remote transfer protocols only report commits for refs. So Git knows the SHA1 of the commit pointed to by HEAD and all other refs; it then has to deduce the value of HEAD by finding a branch that points to the same commit. This means that if two branches happen to point there, it's ambiguous. (I believe it picks master if possible, then falls back to first alphabetically.) You'll see this reported in the output of git remote show origin:



$ git remote show origin
* remote origin
Fetch URL: ...
Push URL: ...
HEAD branch (remote HEAD is ambiguous, may be one of the following):
foo
master


Oddly, although the notion of HEAD printed this way will change if things change on the remote (e.g. if foo is removed), it doesn't actually update refs/remotes/origin/HEAD. This can lead to really odd situations. Say that in the above example origin/HEAD actually pointed to foo, and origin's foo branch was then removed. We can then do this:



$ git remote show origin
...
HEAD branch: master
$ git symbolic-ref refs/remotes/origin/HEAD
refs/remotes/origin/foo
$ git remote update --prune origin
Fetching origin
x [deleted] (none) -> origin/foo
(refs/remotes/origin/HEAD has become dangling)


So even though remote show knows HEAD is master, it doesn't update anything. The stale foo branch is correctly pruned, and HEAD becomes dangling (pointing to a nonexistent branch), and it still doesn't update it to point to master. If you want to fix this, use git remote set-head origin -a, which automatically determines origin's HEAD as above, and then actually sets origin/HEAD to point to the appropriate remote branch.






share|improve this answer


























  • @jefromi Awesome answer! Just a remark: you write that HEAD is a symbolic ref, pointing to a branch instead of directly to a commit [...], but it might be worth mentioning "detached HEAD state", for completeness.

    – jubobs
    Aug 21 '14 at 13:26








  • 1





    Please see my update: stackoverflow.com/a/25430727/2541573

    – jubobs
    Aug 21 '14 at 16:18






  • 2





    @Jubobs Thanks! If my answer needs updating, please feel free to simply edit it, though - it'll certainly save people time to read a brief summary of how things actually work, rather than having to sort through what was true two years ago and what's true now.

    – Cascabel
    Aug 21 '14 at 18:35











  • have read this at least 5 times and still do no understand a bit of it

    – krb686
    Feb 26 '15 at 15:19











  • git remote set-head origin -a did the job for me

    – Shujito
    May 29 '18 at 19:09



















53














It is your setting as the owner of your local repo. Change it like this:



git remote set-head origin some_branch


And origin/HEAD will point to your branch instead of master. This would then apply to your repo only and not for others. By default, it will point to master, unless something else has been configured on the remote repo.



Manual entry for remote set-head provides some good information on this.



Edit: to emphasize: without you telling it to, the only way it would "move" would be a case like renaming the master branch, which I don't think is considered "organic". So, I would say organically it does not move.






share|improve this answer





















  • 1





    The edit emphasis isn't completely correct here. It can also change if you clone from a local copy that isn't on master branch.

    – mphair
    May 15 '14 at 7:13











  • I don't consider a clone "moving", but I guess we can disagree on that :)

    – eis
    Sep 1 '17 at 7:06



















18














What moves origin/HEAD "organically"?





  • git clone sets it once to the spot where HEAD is on origin


    • it serves as the default branch to checkout after cloning with git clone




What does HEAD on origin represent?




  • on bare repositories (often repositories “on servers”) it serves as a marker for the default branch, because git clone uses it in such a way

  • on non-bare repositories (local or remote), it reflects the repository’s current checkout


What sets origin/HEAD?





  • git clone fetches and sets it

  • it would make sense if git fetch updates it like any other reference, but it doesn’t


  • git remote set-head origin -a fetches and sets it


    • useful to update the local knowledge of what remote considers the “default branch”




Trivia





  • origin/HEAD can also be set to any other value without contacting the remote: git remote set-head origin <branch>


    • I see no use-case for this, except for testing



  • unfortunately nothing is able to set HEAD on the remote

  • older versions of git did not know which branch HEAD points to on the remote, only which commit hash it finally has: so it just hopefully picked a branch name pointing to the same hash






share|improve this answer


























  • I had lost reference to origin/HEAD and your solution helped. Thanks!

    – java_dude
    Apr 5 '15 at 23:32













  • I disagree with git fetch updating it, since it allows to configure a (local) shortcut. Quoting the doc: "Having a default branch for a remote is not required, but allows the name of the remote to be specified in lieu of a specific branch". It would be strange if a remote change would update locally configured shortcuts.

    – Micha Wiedenmann
    Nov 21 '18 at 7:51



















8














Disclaimer: this is an update to Jefromi's answer, which I'm writing to save the curious some time.



I tried in vain to replicate (in Git 2.0.1) the remote HEAD is ambiguous message that Jefromi mentions in his answer; so I did a bit of digging (by cloning https://github.com/git/git and searching the log). It used to be that




Determining HEAD is ambiguous since it is done by comparing SHA1s.

In the case of multiple matches we return refs/heads/master if it
matches, else we return the first match we encounter. builtin-remote
needs all matches returned to it, so add a flag for it to request such.



(Commit 4229f1fa325870d6b24fe2a4c7d2ed5f14c6f771, dated Feb 27, 2009, found with git log --reverse --grep="HEAD is ambiguous")



However, the ambiguity in question has since been lifted:




One long-standing flaw in the pack transfer protocol used by "git
clone" was that there was no way to tell the other end which branch
"HEAD" points at, and the receiving end needed to guess. A new
capability has been defined in the pack protocol to convey this
information so that cloning from a repository with more than one
branches pointing at the same commit where the HEAD is at now
reliably sets the initial branch in the resulting repository.



(Commit 9196a2f8bd46d36a285bdfa03b4540ed3f01f671, dated Nov 8, 2013, found with git log --grep="ambiguous" --grep="HEAD" --all-match)



Edit (thanks to torek):



$ git name-rev --name-only 9196a2f8bd46d36a285bdfa03b4540ed3f01f671
tags/v1.8.4.3~3


This means that, if you're using Git v1.8.4.3 or later, you shouldn't run into any ambiguous-remote-HEAD problem.






share|improve this answer





















  • 1





    Based on the tags in the git source, this fix applies to git version 1.8.4.3 and later.

    – torek
    Aug 21 '14 at 18:08











  • I need 1.8.4.3 or later on both sides, right?

    – Robert Siemer
    Jan 20 '15 at 13:00











  • @RobertSiemer I'm not sure, but I think so, yes.

    – jubobs
    Jan 20 '15 at 14:00



















7














Remember there are two independent git repos we are talking about. Your local repo with your code and the remote running somewhere else.



Your are right, when you change a branch, HEAD points to your current branch. All of this is happening on your local git repo. Not the remote repo, which could be owned by another developer, or siting on a sever in your office, or github, or another directory on the filesystem, or etc...



Your computer (local repo) has no business changing the HEAD pointer on the remote git repo. It could be owned by a different developer for example.



One more thing, what your computer calls origin/XXX is your computer's understanding of the state of the remote at the time of the last fetch.



So what would "organically" update origin/HEAD? It would be activity on the remote git repo. Not your local repo.



People have mentioned




git symbolic-ref HEAD refs/head/my_other_branch




Normally, that is used when there is a shared central git repo on a server for use by the development team. It would be a command executed on the remote computer. You would see this as activity on the remote git repo.






share|improve this answer


























  • Sorry, if I'm a little repetitive. I just want to point out the fact that git is a distributed version control system, and as such the two repos are independent.

    – Pablo Maurin
    Jan 12 '12 at 19:25











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8839958%2fhow-does-origin-head-get-set%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























5 Answers
5






active

oldest

votes








5 Answers
5






active

oldest

votes









active

oldest

votes






active

oldest

votes









141














Note first that your question shows a bit of misunderstanding. origin/HEAD represents the default branch on the remote, i.e. the HEAD that's in that remote repository you're calling origin. When you switch branches in your repo, you're not affecting that. The same is true for remote branches; you might have master and origin/master in your repo, where origin/master represents a local copy of the master branch in the remote repository.



origin's HEAD will only change if you or someone else actually changes it in the remote repository, which should basically never happen - you want the default branch a public repo to stay constant, on the stable branch (probably master). origin/HEAD is a local ref representing a local copy of the HEAD in the remote repository. (Its full name is refs/remotes/origin/HEAD.)



I think the above answers what you actually wanted to know, but to go ahead and answer the question you explicitly asked... origin/HEAD is set automatically when you clone a repository, and that's about it. Bizarrely, that it's not set by commands like git remote update - I believe the only way it will change is if you manually change it. (By change I mean point to a different branch; obviously the commit it points to changes if that branch changes, which might happen on fetch/pull/remote update.)





Edit: The problem discussed below was corrected in Git 1.8.4.3; see this update.





There is a tiny caveat, though. HEAD is a symbolic ref, pointing to a branch instead of directly to a commit, but the git remote transfer protocols only report commits for refs. So Git knows the SHA1 of the commit pointed to by HEAD and all other refs; it then has to deduce the value of HEAD by finding a branch that points to the same commit. This means that if two branches happen to point there, it's ambiguous. (I believe it picks master if possible, then falls back to first alphabetically.) You'll see this reported in the output of git remote show origin:



$ git remote show origin
* remote origin
Fetch URL: ...
Push URL: ...
HEAD branch (remote HEAD is ambiguous, may be one of the following):
foo
master


Oddly, although the notion of HEAD printed this way will change if things change on the remote (e.g. if foo is removed), it doesn't actually update refs/remotes/origin/HEAD. This can lead to really odd situations. Say that in the above example origin/HEAD actually pointed to foo, and origin's foo branch was then removed. We can then do this:



$ git remote show origin
...
HEAD branch: master
$ git symbolic-ref refs/remotes/origin/HEAD
refs/remotes/origin/foo
$ git remote update --prune origin
Fetching origin
x [deleted] (none) -> origin/foo
(refs/remotes/origin/HEAD has become dangling)


So even though remote show knows HEAD is master, it doesn't update anything. The stale foo branch is correctly pruned, and HEAD becomes dangling (pointing to a nonexistent branch), and it still doesn't update it to point to master. If you want to fix this, use git remote set-head origin -a, which automatically determines origin's HEAD as above, and then actually sets origin/HEAD to point to the appropriate remote branch.






share|improve this answer


























  • @jefromi Awesome answer! Just a remark: you write that HEAD is a symbolic ref, pointing to a branch instead of directly to a commit [...], but it might be worth mentioning "detached HEAD state", for completeness.

    – jubobs
    Aug 21 '14 at 13:26








  • 1





    Please see my update: stackoverflow.com/a/25430727/2541573

    – jubobs
    Aug 21 '14 at 16:18






  • 2





    @Jubobs Thanks! If my answer needs updating, please feel free to simply edit it, though - it'll certainly save people time to read a brief summary of how things actually work, rather than having to sort through what was true two years ago and what's true now.

    – Cascabel
    Aug 21 '14 at 18:35











  • have read this at least 5 times and still do no understand a bit of it

    – krb686
    Feb 26 '15 at 15:19











  • git remote set-head origin -a did the job for me

    – Shujito
    May 29 '18 at 19:09
















141














Note first that your question shows a bit of misunderstanding. origin/HEAD represents the default branch on the remote, i.e. the HEAD that's in that remote repository you're calling origin. When you switch branches in your repo, you're not affecting that. The same is true for remote branches; you might have master and origin/master in your repo, where origin/master represents a local copy of the master branch in the remote repository.



origin's HEAD will only change if you or someone else actually changes it in the remote repository, which should basically never happen - you want the default branch a public repo to stay constant, on the stable branch (probably master). origin/HEAD is a local ref representing a local copy of the HEAD in the remote repository. (Its full name is refs/remotes/origin/HEAD.)



I think the above answers what you actually wanted to know, but to go ahead and answer the question you explicitly asked... origin/HEAD is set automatically when you clone a repository, and that's about it. Bizarrely, that it's not set by commands like git remote update - I believe the only way it will change is if you manually change it. (By change I mean point to a different branch; obviously the commit it points to changes if that branch changes, which might happen on fetch/pull/remote update.)





Edit: The problem discussed below was corrected in Git 1.8.4.3; see this update.





There is a tiny caveat, though. HEAD is a symbolic ref, pointing to a branch instead of directly to a commit, but the git remote transfer protocols only report commits for refs. So Git knows the SHA1 of the commit pointed to by HEAD and all other refs; it then has to deduce the value of HEAD by finding a branch that points to the same commit. This means that if two branches happen to point there, it's ambiguous. (I believe it picks master if possible, then falls back to first alphabetically.) You'll see this reported in the output of git remote show origin:



$ git remote show origin
* remote origin
Fetch URL: ...
Push URL: ...
HEAD branch (remote HEAD is ambiguous, may be one of the following):
foo
master


Oddly, although the notion of HEAD printed this way will change if things change on the remote (e.g. if foo is removed), it doesn't actually update refs/remotes/origin/HEAD. This can lead to really odd situations. Say that in the above example origin/HEAD actually pointed to foo, and origin's foo branch was then removed. We can then do this:



$ git remote show origin
...
HEAD branch: master
$ git symbolic-ref refs/remotes/origin/HEAD
refs/remotes/origin/foo
$ git remote update --prune origin
Fetching origin
x [deleted] (none) -> origin/foo
(refs/remotes/origin/HEAD has become dangling)


So even though remote show knows HEAD is master, it doesn't update anything. The stale foo branch is correctly pruned, and HEAD becomes dangling (pointing to a nonexistent branch), and it still doesn't update it to point to master. If you want to fix this, use git remote set-head origin -a, which automatically determines origin's HEAD as above, and then actually sets origin/HEAD to point to the appropriate remote branch.






share|improve this answer


























  • @jefromi Awesome answer! Just a remark: you write that HEAD is a symbolic ref, pointing to a branch instead of directly to a commit [...], but it might be worth mentioning "detached HEAD state", for completeness.

    – jubobs
    Aug 21 '14 at 13:26








  • 1





    Please see my update: stackoverflow.com/a/25430727/2541573

    – jubobs
    Aug 21 '14 at 16:18






  • 2





    @Jubobs Thanks! If my answer needs updating, please feel free to simply edit it, though - it'll certainly save people time to read a brief summary of how things actually work, rather than having to sort through what was true two years ago and what's true now.

    – Cascabel
    Aug 21 '14 at 18:35











  • have read this at least 5 times and still do no understand a bit of it

    – krb686
    Feb 26 '15 at 15:19











  • git remote set-head origin -a did the job for me

    – Shujito
    May 29 '18 at 19:09














141












141








141







Note first that your question shows a bit of misunderstanding. origin/HEAD represents the default branch on the remote, i.e. the HEAD that's in that remote repository you're calling origin. When you switch branches in your repo, you're not affecting that. The same is true for remote branches; you might have master and origin/master in your repo, where origin/master represents a local copy of the master branch in the remote repository.



origin's HEAD will only change if you or someone else actually changes it in the remote repository, which should basically never happen - you want the default branch a public repo to stay constant, on the stable branch (probably master). origin/HEAD is a local ref representing a local copy of the HEAD in the remote repository. (Its full name is refs/remotes/origin/HEAD.)



I think the above answers what you actually wanted to know, but to go ahead and answer the question you explicitly asked... origin/HEAD is set automatically when you clone a repository, and that's about it. Bizarrely, that it's not set by commands like git remote update - I believe the only way it will change is if you manually change it. (By change I mean point to a different branch; obviously the commit it points to changes if that branch changes, which might happen on fetch/pull/remote update.)





Edit: The problem discussed below was corrected in Git 1.8.4.3; see this update.





There is a tiny caveat, though. HEAD is a symbolic ref, pointing to a branch instead of directly to a commit, but the git remote transfer protocols only report commits for refs. So Git knows the SHA1 of the commit pointed to by HEAD and all other refs; it then has to deduce the value of HEAD by finding a branch that points to the same commit. This means that if two branches happen to point there, it's ambiguous. (I believe it picks master if possible, then falls back to first alphabetically.) You'll see this reported in the output of git remote show origin:



$ git remote show origin
* remote origin
Fetch URL: ...
Push URL: ...
HEAD branch (remote HEAD is ambiguous, may be one of the following):
foo
master


Oddly, although the notion of HEAD printed this way will change if things change on the remote (e.g. if foo is removed), it doesn't actually update refs/remotes/origin/HEAD. This can lead to really odd situations. Say that in the above example origin/HEAD actually pointed to foo, and origin's foo branch was then removed. We can then do this:



$ git remote show origin
...
HEAD branch: master
$ git symbolic-ref refs/remotes/origin/HEAD
refs/remotes/origin/foo
$ git remote update --prune origin
Fetching origin
x [deleted] (none) -> origin/foo
(refs/remotes/origin/HEAD has become dangling)


So even though remote show knows HEAD is master, it doesn't update anything. The stale foo branch is correctly pruned, and HEAD becomes dangling (pointing to a nonexistent branch), and it still doesn't update it to point to master. If you want to fix this, use git remote set-head origin -a, which automatically determines origin's HEAD as above, and then actually sets origin/HEAD to point to the appropriate remote branch.






share|improve this answer















Note first that your question shows a bit of misunderstanding. origin/HEAD represents the default branch on the remote, i.e. the HEAD that's in that remote repository you're calling origin. When you switch branches in your repo, you're not affecting that. The same is true for remote branches; you might have master and origin/master in your repo, where origin/master represents a local copy of the master branch in the remote repository.



origin's HEAD will only change if you or someone else actually changes it in the remote repository, which should basically never happen - you want the default branch a public repo to stay constant, on the stable branch (probably master). origin/HEAD is a local ref representing a local copy of the HEAD in the remote repository. (Its full name is refs/remotes/origin/HEAD.)



I think the above answers what you actually wanted to know, but to go ahead and answer the question you explicitly asked... origin/HEAD is set automatically when you clone a repository, and that's about it. Bizarrely, that it's not set by commands like git remote update - I believe the only way it will change is if you manually change it. (By change I mean point to a different branch; obviously the commit it points to changes if that branch changes, which might happen on fetch/pull/remote update.)





Edit: The problem discussed below was corrected in Git 1.8.4.3; see this update.





There is a tiny caveat, though. HEAD is a symbolic ref, pointing to a branch instead of directly to a commit, but the git remote transfer protocols only report commits for refs. So Git knows the SHA1 of the commit pointed to by HEAD and all other refs; it then has to deduce the value of HEAD by finding a branch that points to the same commit. This means that if two branches happen to point there, it's ambiguous. (I believe it picks master if possible, then falls back to first alphabetically.) You'll see this reported in the output of git remote show origin:



$ git remote show origin
* remote origin
Fetch URL: ...
Push URL: ...
HEAD branch (remote HEAD is ambiguous, may be one of the following):
foo
master


Oddly, although the notion of HEAD printed this way will change if things change on the remote (e.g. if foo is removed), it doesn't actually update refs/remotes/origin/HEAD. This can lead to really odd situations. Say that in the above example origin/HEAD actually pointed to foo, and origin's foo branch was then removed. We can then do this:



$ git remote show origin
...
HEAD branch: master
$ git symbolic-ref refs/remotes/origin/HEAD
refs/remotes/origin/foo
$ git remote update --prune origin
Fetching origin
x [deleted] (none) -> origin/foo
(refs/remotes/origin/HEAD has become dangling)


So even though remote show knows HEAD is master, it doesn't update anything. The stale foo branch is correctly pruned, and HEAD becomes dangling (pointing to a nonexistent branch), and it still doesn't update it to point to master. If you want to fix this, use git remote set-head origin -a, which automatically determines origin's HEAD as above, and then actually sets origin/HEAD to point to the appropriate remote branch.







share|improve this answer














share|improve this answer



share|improve this answer








edited May 23 '17 at 10:31









Community

11




11










answered Jan 12 '12 at 19:22









CascabelCascabel

332k56325293




332k56325293













  • @jefromi Awesome answer! Just a remark: you write that HEAD is a symbolic ref, pointing to a branch instead of directly to a commit [...], but it might be worth mentioning "detached HEAD state", for completeness.

    – jubobs
    Aug 21 '14 at 13:26








  • 1





    Please see my update: stackoverflow.com/a/25430727/2541573

    – jubobs
    Aug 21 '14 at 16:18






  • 2





    @Jubobs Thanks! If my answer needs updating, please feel free to simply edit it, though - it'll certainly save people time to read a brief summary of how things actually work, rather than having to sort through what was true two years ago and what's true now.

    – Cascabel
    Aug 21 '14 at 18:35











  • have read this at least 5 times and still do no understand a bit of it

    – krb686
    Feb 26 '15 at 15:19











  • git remote set-head origin -a did the job for me

    – Shujito
    May 29 '18 at 19:09



















  • @jefromi Awesome answer! Just a remark: you write that HEAD is a symbolic ref, pointing to a branch instead of directly to a commit [...], but it might be worth mentioning "detached HEAD state", for completeness.

    – jubobs
    Aug 21 '14 at 13:26








  • 1





    Please see my update: stackoverflow.com/a/25430727/2541573

    – jubobs
    Aug 21 '14 at 16:18






  • 2





    @Jubobs Thanks! If my answer needs updating, please feel free to simply edit it, though - it'll certainly save people time to read a brief summary of how things actually work, rather than having to sort through what was true two years ago and what's true now.

    – Cascabel
    Aug 21 '14 at 18:35











  • have read this at least 5 times and still do no understand a bit of it

    – krb686
    Feb 26 '15 at 15:19











  • git remote set-head origin -a did the job for me

    – Shujito
    May 29 '18 at 19:09

















@jefromi Awesome answer! Just a remark: you write that HEAD is a symbolic ref, pointing to a branch instead of directly to a commit [...], but it might be worth mentioning "detached HEAD state", for completeness.

– jubobs
Aug 21 '14 at 13:26







@jefromi Awesome answer! Just a remark: you write that HEAD is a symbolic ref, pointing to a branch instead of directly to a commit [...], but it might be worth mentioning "detached HEAD state", for completeness.

– jubobs
Aug 21 '14 at 13:26






1




1





Please see my update: stackoverflow.com/a/25430727/2541573

– jubobs
Aug 21 '14 at 16:18





Please see my update: stackoverflow.com/a/25430727/2541573

– jubobs
Aug 21 '14 at 16:18




2




2





@Jubobs Thanks! If my answer needs updating, please feel free to simply edit it, though - it'll certainly save people time to read a brief summary of how things actually work, rather than having to sort through what was true two years ago and what's true now.

– Cascabel
Aug 21 '14 at 18:35





@Jubobs Thanks! If my answer needs updating, please feel free to simply edit it, though - it'll certainly save people time to read a brief summary of how things actually work, rather than having to sort through what was true two years ago and what's true now.

– Cascabel
Aug 21 '14 at 18:35













have read this at least 5 times and still do no understand a bit of it

– krb686
Feb 26 '15 at 15:19





have read this at least 5 times and still do no understand a bit of it

– krb686
Feb 26 '15 at 15:19













git remote set-head origin -a did the job for me

– Shujito
May 29 '18 at 19:09





git remote set-head origin -a did the job for me

– Shujito
May 29 '18 at 19:09













53














It is your setting as the owner of your local repo. Change it like this:



git remote set-head origin some_branch


And origin/HEAD will point to your branch instead of master. This would then apply to your repo only and not for others. By default, it will point to master, unless something else has been configured on the remote repo.



Manual entry for remote set-head provides some good information on this.



Edit: to emphasize: without you telling it to, the only way it would "move" would be a case like renaming the master branch, which I don't think is considered "organic". So, I would say organically it does not move.






share|improve this answer





















  • 1





    The edit emphasis isn't completely correct here. It can also change if you clone from a local copy that isn't on master branch.

    – mphair
    May 15 '14 at 7:13











  • I don't consider a clone "moving", but I guess we can disagree on that :)

    – eis
    Sep 1 '17 at 7:06
















53














It is your setting as the owner of your local repo. Change it like this:



git remote set-head origin some_branch


And origin/HEAD will point to your branch instead of master. This would then apply to your repo only and not for others. By default, it will point to master, unless something else has been configured on the remote repo.



Manual entry for remote set-head provides some good information on this.



Edit: to emphasize: without you telling it to, the only way it would "move" would be a case like renaming the master branch, which I don't think is considered "organic". So, I would say organically it does not move.






share|improve this answer





















  • 1





    The edit emphasis isn't completely correct here. It can also change if you clone from a local copy that isn't on master branch.

    – mphair
    May 15 '14 at 7:13











  • I don't consider a clone "moving", but I guess we can disagree on that :)

    – eis
    Sep 1 '17 at 7:06














53












53








53







It is your setting as the owner of your local repo. Change it like this:



git remote set-head origin some_branch


And origin/HEAD will point to your branch instead of master. This would then apply to your repo only and not for others. By default, it will point to master, unless something else has been configured on the remote repo.



Manual entry for remote set-head provides some good information on this.



Edit: to emphasize: without you telling it to, the only way it would "move" would be a case like renaming the master branch, which I don't think is considered "organic". So, I would say organically it does not move.






share|improve this answer















It is your setting as the owner of your local repo. Change it like this:



git remote set-head origin some_branch


And origin/HEAD will point to your branch instead of master. This would then apply to your repo only and not for others. By default, it will point to master, unless something else has been configured on the remote repo.



Manual entry for remote set-head provides some good information on this.



Edit: to emphasize: without you telling it to, the only way it would "move" would be a case like renaming the master branch, which I don't think is considered "organic". So, I would say organically it does not move.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 12:33

























answered Jan 12 '12 at 18:42









eiseis

34.7k896144




34.7k896144








  • 1





    The edit emphasis isn't completely correct here. It can also change if you clone from a local copy that isn't on master branch.

    – mphair
    May 15 '14 at 7:13











  • I don't consider a clone "moving", but I guess we can disagree on that :)

    – eis
    Sep 1 '17 at 7:06














  • 1





    The edit emphasis isn't completely correct here. It can also change if you clone from a local copy that isn't on master branch.

    – mphair
    May 15 '14 at 7:13











  • I don't consider a clone "moving", but I guess we can disagree on that :)

    – eis
    Sep 1 '17 at 7:06








1




1





The edit emphasis isn't completely correct here. It can also change if you clone from a local copy that isn't on master branch.

– mphair
May 15 '14 at 7:13





The edit emphasis isn't completely correct here. It can also change if you clone from a local copy that isn't on master branch.

– mphair
May 15 '14 at 7:13













I don't consider a clone "moving", but I guess we can disagree on that :)

– eis
Sep 1 '17 at 7:06





I don't consider a clone "moving", but I guess we can disagree on that :)

– eis
Sep 1 '17 at 7:06











18














What moves origin/HEAD "organically"?





  • git clone sets it once to the spot where HEAD is on origin


    • it serves as the default branch to checkout after cloning with git clone




What does HEAD on origin represent?




  • on bare repositories (often repositories “on servers”) it serves as a marker for the default branch, because git clone uses it in such a way

  • on non-bare repositories (local or remote), it reflects the repository’s current checkout


What sets origin/HEAD?





  • git clone fetches and sets it

  • it would make sense if git fetch updates it like any other reference, but it doesn’t


  • git remote set-head origin -a fetches and sets it


    • useful to update the local knowledge of what remote considers the “default branch”




Trivia





  • origin/HEAD can also be set to any other value without contacting the remote: git remote set-head origin <branch>


    • I see no use-case for this, except for testing



  • unfortunately nothing is able to set HEAD on the remote

  • older versions of git did not know which branch HEAD points to on the remote, only which commit hash it finally has: so it just hopefully picked a branch name pointing to the same hash






share|improve this answer


























  • I had lost reference to origin/HEAD and your solution helped. Thanks!

    – java_dude
    Apr 5 '15 at 23:32













  • I disagree with git fetch updating it, since it allows to configure a (local) shortcut. Quoting the doc: "Having a default branch for a remote is not required, but allows the name of the remote to be specified in lieu of a specific branch". It would be strange if a remote change would update locally configured shortcuts.

    – Micha Wiedenmann
    Nov 21 '18 at 7:51
















18














What moves origin/HEAD "organically"?





  • git clone sets it once to the spot where HEAD is on origin


    • it serves as the default branch to checkout after cloning with git clone




What does HEAD on origin represent?




  • on bare repositories (often repositories “on servers”) it serves as a marker for the default branch, because git clone uses it in such a way

  • on non-bare repositories (local or remote), it reflects the repository’s current checkout


What sets origin/HEAD?





  • git clone fetches and sets it

  • it would make sense if git fetch updates it like any other reference, but it doesn’t


  • git remote set-head origin -a fetches and sets it


    • useful to update the local knowledge of what remote considers the “default branch”




Trivia





  • origin/HEAD can also be set to any other value without contacting the remote: git remote set-head origin <branch>


    • I see no use-case for this, except for testing



  • unfortunately nothing is able to set HEAD on the remote

  • older versions of git did not know which branch HEAD points to on the remote, only which commit hash it finally has: so it just hopefully picked a branch name pointing to the same hash






share|improve this answer


























  • I had lost reference to origin/HEAD and your solution helped. Thanks!

    – java_dude
    Apr 5 '15 at 23:32













  • I disagree with git fetch updating it, since it allows to configure a (local) shortcut. Quoting the doc: "Having a default branch for a remote is not required, but allows the name of the remote to be specified in lieu of a specific branch". It would be strange if a remote change would update locally configured shortcuts.

    – Micha Wiedenmann
    Nov 21 '18 at 7:51














18












18








18







What moves origin/HEAD "organically"?





  • git clone sets it once to the spot where HEAD is on origin


    • it serves as the default branch to checkout after cloning with git clone




What does HEAD on origin represent?




  • on bare repositories (often repositories “on servers”) it serves as a marker for the default branch, because git clone uses it in such a way

  • on non-bare repositories (local or remote), it reflects the repository’s current checkout


What sets origin/HEAD?





  • git clone fetches and sets it

  • it would make sense if git fetch updates it like any other reference, but it doesn’t


  • git remote set-head origin -a fetches and sets it


    • useful to update the local knowledge of what remote considers the “default branch”




Trivia





  • origin/HEAD can also be set to any other value without contacting the remote: git remote set-head origin <branch>


    • I see no use-case for this, except for testing



  • unfortunately nothing is able to set HEAD on the remote

  • older versions of git did not know which branch HEAD points to on the remote, only which commit hash it finally has: so it just hopefully picked a branch name pointing to the same hash






share|improve this answer















What moves origin/HEAD "organically"?





  • git clone sets it once to the spot where HEAD is on origin


    • it serves as the default branch to checkout after cloning with git clone




What does HEAD on origin represent?




  • on bare repositories (often repositories “on servers”) it serves as a marker for the default branch, because git clone uses it in such a way

  • on non-bare repositories (local or remote), it reflects the repository’s current checkout


What sets origin/HEAD?





  • git clone fetches and sets it

  • it would make sense if git fetch updates it like any other reference, but it doesn’t


  • git remote set-head origin -a fetches and sets it


    • useful to update the local knowledge of what remote considers the “default branch”




Trivia





  • origin/HEAD can also be set to any other value without contacting the remote: git remote set-head origin <branch>


    • I see no use-case for this, except for testing



  • unfortunately nothing is able to set HEAD on the remote

  • older versions of git did not know which branch HEAD points to on the remote, only which commit hash it finally has: so it just hopefully picked a branch name pointing to the same hash







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 22 '17 at 16:23

























answered Apr 2 '15 at 5:47









Robert SiemerRobert Siemer

17.5k74974




17.5k74974













  • I had lost reference to origin/HEAD and your solution helped. Thanks!

    – java_dude
    Apr 5 '15 at 23:32













  • I disagree with git fetch updating it, since it allows to configure a (local) shortcut. Quoting the doc: "Having a default branch for a remote is not required, but allows the name of the remote to be specified in lieu of a specific branch". It would be strange if a remote change would update locally configured shortcuts.

    – Micha Wiedenmann
    Nov 21 '18 at 7:51



















  • I had lost reference to origin/HEAD and your solution helped. Thanks!

    – java_dude
    Apr 5 '15 at 23:32













  • I disagree with git fetch updating it, since it allows to configure a (local) shortcut. Quoting the doc: "Having a default branch for a remote is not required, but allows the name of the remote to be specified in lieu of a specific branch". It would be strange if a remote change would update locally configured shortcuts.

    – Micha Wiedenmann
    Nov 21 '18 at 7:51

















I had lost reference to origin/HEAD and your solution helped. Thanks!

– java_dude
Apr 5 '15 at 23:32







I had lost reference to origin/HEAD and your solution helped. Thanks!

– java_dude
Apr 5 '15 at 23:32















I disagree with git fetch updating it, since it allows to configure a (local) shortcut. Quoting the doc: "Having a default branch for a remote is not required, but allows the name of the remote to be specified in lieu of a specific branch". It would be strange if a remote change would update locally configured shortcuts.

– Micha Wiedenmann
Nov 21 '18 at 7:51





I disagree with git fetch updating it, since it allows to configure a (local) shortcut. Quoting the doc: "Having a default branch for a remote is not required, but allows the name of the remote to be specified in lieu of a specific branch". It would be strange if a remote change would update locally configured shortcuts.

– Micha Wiedenmann
Nov 21 '18 at 7:51











8














Disclaimer: this is an update to Jefromi's answer, which I'm writing to save the curious some time.



I tried in vain to replicate (in Git 2.0.1) the remote HEAD is ambiguous message that Jefromi mentions in his answer; so I did a bit of digging (by cloning https://github.com/git/git and searching the log). It used to be that




Determining HEAD is ambiguous since it is done by comparing SHA1s.

In the case of multiple matches we return refs/heads/master if it
matches, else we return the first match we encounter. builtin-remote
needs all matches returned to it, so add a flag for it to request such.



(Commit 4229f1fa325870d6b24fe2a4c7d2ed5f14c6f771, dated Feb 27, 2009, found with git log --reverse --grep="HEAD is ambiguous")



However, the ambiguity in question has since been lifted:




One long-standing flaw in the pack transfer protocol used by "git
clone" was that there was no way to tell the other end which branch
"HEAD" points at, and the receiving end needed to guess. A new
capability has been defined in the pack protocol to convey this
information so that cloning from a repository with more than one
branches pointing at the same commit where the HEAD is at now
reliably sets the initial branch in the resulting repository.



(Commit 9196a2f8bd46d36a285bdfa03b4540ed3f01f671, dated Nov 8, 2013, found with git log --grep="ambiguous" --grep="HEAD" --all-match)



Edit (thanks to torek):



$ git name-rev --name-only 9196a2f8bd46d36a285bdfa03b4540ed3f01f671
tags/v1.8.4.3~3


This means that, if you're using Git v1.8.4.3 or later, you shouldn't run into any ambiguous-remote-HEAD problem.






share|improve this answer





















  • 1





    Based on the tags in the git source, this fix applies to git version 1.8.4.3 and later.

    – torek
    Aug 21 '14 at 18:08











  • I need 1.8.4.3 or later on both sides, right?

    – Robert Siemer
    Jan 20 '15 at 13:00











  • @RobertSiemer I'm not sure, but I think so, yes.

    – jubobs
    Jan 20 '15 at 14:00
















8














Disclaimer: this is an update to Jefromi's answer, which I'm writing to save the curious some time.



I tried in vain to replicate (in Git 2.0.1) the remote HEAD is ambiguous message that Jefromi mentions in his answer; so I did a bit of digging (by cloning https://github.com/git/git and searching the log). It used to be that




Determining HEAD is ambiguous since it is done by comparing SHA1s.

In the case of multiple matches we return refs/heads/master if it
matches, else we return the first match we encounter. builtin-remote
needs all matches returned to it, so add a flag for it to request such.



(Commit 4229f1fa325870d6b24fe2a4c7d2ed5f14c6f771, dated Feb 27, 2009, found with git log --reverse --grep="HEAD is ambiguous")



However, the ambiguity in question has since been lifted:




One long-standing flaw in the pack transfer protocol used by "git
clone" was that there was no way to tell the other end which branch
"HEAD" points at, and the receiving end needed to guess. A new
capability has been defined in the pack protocol to convey this
information so that cloning from a repository with more than one
branches pointing at the same commit where the HEAD is at now
reliably sets the initial branch in the resulting repository.



(Commit 9196a2f8bd46d36a285bdfa03b4540ed3f01f671, dated Nov 8, 2013, found with git log --grep="ambiguous" --grep="HEAD" --all-match)



Edit (thanks to torek):



$ git name-rev --name-only 9196a2f8bd46d36a285bdfa03b4540ed3f01f671
tags/v1.8.4.3~3


This means that, if you're using Git v1.8.4.3 or later, you shouldn't run into any ambiguous-remote-HEAD problem.






share|improve this answer





















  • 1





    Based on the tags in the git source, this fix applies to git version 1.8.4.3 and later.

    – torek
    Aug 21 '14 at 18:08











  • I need 1.8.4.3 or later on both sides, right?

    – Robert Siemer
    Jan 20 '15 at 13:00











  • @RobertSiemer I'm not sure, but I think so, yes.

    – jubobs
    Jan 20 '15 at 14:00














8












8








8







Disclaimer: this is an update to Jefromi's answer, which I'm writing to save the curious some time.



I tried in vain to replicate (in Git 2.0.1) the remote HEAD is ambiguous message that Jefromi mentions in his answer; so I did a bit of digging (by cloning https://github.com/git/git and searching the log). It used to be that




Determining HEAD is ambiguous since it is done by comparing SHA1s.

In the case of multiple matches we return refs/heads/master if it
matches, else we return the first match we encounter. builtin-remote
needs all matches returned to it, so add a flag for it to request such.



(Commit 4229f1fa325870d6b24fe2a4c7d2ed5f14c6f771, dated Feb 27, 2009, found with git log --reverse --grep="HEAD is ambiguous")



However, the ambiguity in question has since been lifted:




One long-standing flaw in the pack transfer protocol used by "git
clone" was that there was no way to tell the other end which branch
"HEAD" points at, and the receiving end needed to guess. A new
capability has been defined in the pack protocol to convey this
information so that cloning from a repository with more than one
branches pointing at the same commit where the HEAD is at now
reliably sets the initial branch in the resulting repository.



(Commit 9196a2f8bd46d36a285bdfa03b4540ed3f01f671, dated Nov 8, 2013, found with git log --grep="ambiguous" --grep="HEAD" --all-match)



Edit (thanks to torek):



$ git name-rev --name-only 9196a2f8bd46d36a285bdfa03b4540ed3f01f671
tags/v1.8.4.3~3


This means that, if you're using Git v1.8.4.3 or later, you shouldn't run into any ambiguous-remote-HEAD problem.






share|improve this answer















Disclaimer: this is an update to Jefromi's answer, which I'm writing to save the curious some time.



I tried in vain to replicate (in Git 2.0.1) the remote HEAD is ambiguous message that Jefromi mentions in his answer; so I did a bit of digging (by cloning https://github.com/git/git and searching the log). It used to be that




Determining HEAD is ambiguous since it is done by comparing SHA1s.

In the case of multiple matches we return refs/heads/master if it
matches, else we return the first match we encounter. builtin-remote
needs all matches returned to it, so add a flag for it to request such.



(Commit 4229f1fa325870d6b24fe2a4c7d2ed5f14c6f771, dated Feb 27, 2009, found with git log --reverse --grep="HEAD is ambiguous")



However, the ambiguity in question has since been lifted:




One long-standing flaw in the pack transfer protocol used by "git
clone" was that there was no way to tell the other end which branch
"HEAD" points at, and the receiving end needed to guess. A new
capability has been defined in the pack protocol to convey this
information so that cloning from a repository with more than one
branches pointing at the same commit where the HEAD is at now
reliably sets the initial branch in the resulting repository.



(Commit 9196a2f8bd46d36a285bdfa03b4540ed3f01f671, dated Nov 8, 2013, found with git log --grep="ambiguous" --grep="HEAD" --all-match)



Edit (thanks to torek):



$ git name-rev --name-only 9196a2f8bd46d36a285bdfa03b4540ed3f01f671
tags/v1.8.4.3~3


This means that, if you're using Git v1.8.4.3 or later, you shouldn't run into any ambiguous-remote-HEAD problem.







share|improve this answer














share|improve this answer



share|improve this answer








edited May 23 '17 at 12:02









Community

11




11










answered Aug 21 '14 at 15:53









jubobsjubobs

33.3k17104124




33.3k17104124








  • 1





    Based on the tags in the git source, this fix applies to git version 1.8.4.3 and later.

    – torek
    Aug 21 '14 at 18:08











  • I need 1.8.4.3 or later on both sides, right?

    – Robert Siemer
    Jan 20 '15 at 13:00











  • @RobertSiemer I'm not sure, but I think so, yes.

    – jubobs
    Jan 20 '15 at 14:00














  • 1





    Based on the tags in the git source, this fix applies to git version 1.8.4.3 and later.

    – torek
    Aug 21 '14 at 18:08











  • I need 1.8.4.3 or later on both sides, right?

    – Robert Siemer
    Jan 20 '15 at 13:00











  • @RobertSiemer I'm not sure, but I think so, yes.

    – jubobs
    Jan 20 '15 at 14:00








1




1





Based on the tags in the git source, this fix applies to git version 1.8.4.3 and later.

– torek
Aug 21 '14 at 18:08





Based on the tags in the git source, this fix applies to git version 1.8.4.3 and later.

– torek
Aug 21 '14 at 18:08













I need 1.8.4.3 or later on both sides, right?

– Robert Siemer
Jan 20 '15 at 13:00





I need 1.8.4.3 or later on both sides, right?

– Robert Siemer
Jan 20 '15 at 13:00













@RobertSiemer I'm not sure, but I think so, yes.

– jubobs
Jan 20 '15 at 14:00





@RobertSiemer I'm not sure, but I think so, yes.

– jubobs
Jan 20 '15 at 14:00











7














Remember there are two independent git repos we are talking about. Your local repo with your code and the remote running somewhere else.



Your are right, when you change a branch, HEAD points to your current branch. All of this is happening on your local git repo. Not the remote repo, which could be owned by another developer, or siting on a sever in your office, or github, or another directory on the filesystem, or etc...



Your computer (local repo) has no business changing the HEAD pointer on the remote git repo. It could be owned by a different developer for example.



One more thing, what your computer calls origin/XXX is your computer's understanding of the state of the remote at the time of the last fetch.



So what would "organically" update origin/HEAD? It would be activity on the remote git repo. Not your local repo.



People have mentioned




git symbolic-ref HEAD refs/head/my_other_branch




Normally, that is used when there is a shared central git repo on a server for use by the development team. It would be a command executed on the remote computer. You would see this as activity on the remote git repo.






share|improve this answer


























  • Sorry, if I'm a little repetitive. I just want to point out the fact that git is a distributed version control system, and as such the two repos are independent.

    – Pablo Maurin
    Jan 12 '12 at 19:25
















7














Remember there are two independent git repos we are talking about. Your local repo with your code and the remote running somewhere else.



Your are right, when you change a branch, HEAD points to your current branch. All of this is happening on your local git repo. Not the remote repo, which could be owned by another developer, or siting on a sever in your office, or github, or another directory on the filesystem, or etc...



Your computer (local repo) has no business changing the HEAD pointer on the remote git repo. It could be owned by a different developer for example.



One more thing, what your computer calls origin/XXX is your computer's understanding of the state of the remote at the time of the last fetch.



So what would "organically" update origin/HEAD? It would be activity on the remote git repo. Not your local repo.



People have mentioned




git symbolic-ref HEAD refs/head/my_other_branch




Normally, that is used when there is a shared central git repo on a server for use by the development team. It would be a command executed on the remote computer. You would see this as activity on the remote git repo.






share|improve this answer


























  • Sorry, if I'm a little repetitive. I just want to point out the fact that git is a distributed version control system, and as such the two repos are independent.

    – Pablo Maurin
    Jan 12 '12 at 19:25














7












7








7







Remember there are two independent git repos we are talking about. Your local repo with your code and the remote running somewhere else.



Your are right, when you change a branch, HEAD points to your current branch. All of this is happening on your local git repo. Not the remote repo, which could be owned by another developer, or siting on a sever in your office, or github, or another directory on the filesystem, or etc...



Your computer (local repo) has no business changing the HEAD pointer on the remote git repo. It could be owned by a different developer for example.



One more thing, what your computer calls origin/XXX is your computer's understanding of the state of the remote at the time of the last fetch.



So what would "organically" update origin/HEAD? It would be activity on the remote git repo. Not your local repo.



People have mentioned




git symbolic-ref HEAD refs/head/my_other_branch




Normally, that is used when there is a shared central git repo on a server for use by the development team. It would be a command executed on the remote computer. You would see this as activity on the remote git repo.






share|improve this answer















Remember there are two independent git repos we are talking about. Your local repo with your code and the remote running somewhere else.



Your are right, when you change a branch, HEAD points to your current branch. All of this is happening on your local git repo. Not the remote repo, which could be owned by another developer, or siting on a sever in your office, or github, or another directory on the filesystem, or etc...



Your computer (local repo) has no business changing the HEAD pointer on the remote git repo. It could be owned by a different developer for example.



One more thing, what your computer calls origin/XXX is your computer's understanding of the state of the remote at the time of the last fetch.



So what would "organically" update origin/HEAD? It would be activity on the remote git repo. Not your local repo.



People have mentioned




git symbolic-ref HEAD refs/head/my_other_branch




Normally, that is used when there is a shared central git repo on a server for use by the development team. It would be a command executed on the remote computer. You would see this as activity on the remote git repo.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 12 '12 at 19:32

























answered Jan 12 '12 at 19:22









Pablo MaurinPablo Maurin

1,16211725




1,16211725













  • Sorry, if I'm a little repetitive. I just want to point out the fact that git is a distributed version control system, and as such the two repos are independent.

    – Pablo Maurin
    Jan 12 '12 at 19:25



















  • Sorry, if I'm a little repetitive. I just want to point out the fact that git is a distributed version control system, and as such the two repos are independent.

    – Pablo Maurin
    Jan 12 '12 at 19:25

















Sorry, if I'm a little repetitive. I just want to point out the fact that git is a distributed version control system, and as such the two repos are independent.

– Pablo Maurin
Jan 12 '12 at 19:25





Sorry, if I'm a little repetitive. I just want to point out the fact that git is a distributed version control system, and as such the two repos are independent.

– Pablo Maurin
Jan 12 '12 at 19:25


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8839958%2fhow-does-origin-head-get-set%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]