Information Technology Reference
In-Depth Information
The command to switch a branch in a non-bare repository is:
$ git checkout [branch-name]
Actually, it performs two operations: it changes the reference stored in HEAD , and it
checks out the files. These two operations can also be performed manually:
$ git symbolic-ref HEAD refs/heads/branch-name
$ git reset --hard
In a bare repository you cannot use the commands, such as $ git checkout or
$ git status , that require the working directory. They simply do not make sense.
Working in a bare repository you can change the reference stored in HEAD , but you
cannot reset the working directory.
Therefore, to change a current branch in a bare repository use the following com-
mand:
$ git symbolic-ref HEAD refs/heads/branch-name
This is a low level command that operates on symbolic references. Used with one
parameter, as in $ git symbolic-ref HEAD , the command works as a getter: it
outputs the reference. When two parameters are used, it acts as a setter: the symbolic
reference passed as the first parameter is set to the value passed as a second parameter.
It is worth remembering that the current branch in a clone will be the branch that
was current in the original repository at the time the $ git clone command was is-
sued. This is true that no matter if the original repository was bare or non-bare. You can
change this using the additional parameter -b passed to clone. The commands:
$ git clone -b doc 05-01 05-13-doc-nonbare
$ git clone --bare -b doc 05-01 05-13-doc-bare
would create new clones with the HEAD pointing to refs/heads/doc .
Summary
Search WWH ::




Custom Search