I want to create a new shared git repository for a new project (on a VM).
I ran git --bare init
from /.../git/new_proj.git
, but a master branch is not created in the .../git/new_proj.git/refs/heads
directory. I also ran sudo chmod 777 -R
on my directory, but it didn't help, and still no master is created after the init
command.
Edit: I even tried to use git init
(without the bare flag), but still the master branch was not created.
Google wasn't much help in this matter...
Anyone know what the problem is? Something I'm missing? Thanks!
Master and branch makes no difference for git. So you can use git without a master.
The remote you cloned from might still have a master branch (you could check with git ls-remote origin master ), but you wouldn't have created a local version of that branch by default, because git clone only checks out the remote's HEAD .
Note that, the master branch is the default branch in Git. It is automatically created and used when you initialize a new Git repository. In the next sections of this article below, I am going to show you how to create Git branches, use Git branches and remove Git branches. So, let's move forward.
It's already in the comments on the other answer so far, but this is perfectly normal: a new repository, "bare" or not, has no commits, so it has no references either.
It does have a HEAD
, which is a file named HEAD
in the repository (the .git
directory), containing a symbolic branch name reference. If you cat HEAD
you'll see ref: refs/heads/master
, meaning that the new repository is "on branch master", even though branch master does not yet exist. Again, this is a perfectly normal state of affairs. You're said to be "on an unborn branch", at this point.
When you add one or more commits to this empty repository, the master
branch can—if it's a bare repo, you may be adding this via git push
which may not provide a master
branch, so let's not say "does" :-) although usually master
does—come into existence at that point, with the reference pointing to the new commit (or the new tip commit of a chain of commits).
In any repo (bare or not, again), you can be "on" a branch that does not exist. In particular, in an ordinary repo, you can do:
$ git checkout --orphan newbranch
which puts you "on" newbranch
(by writing ref: refs/heads/newbranch
into HEAD
) without actually creating newbranch
yet, making newbranch
an "unborn branch". The next commit then causes newbranch
to come into existence, and that commit has no parent commits (hence the --orphan
part): it is a new root commit. This is the same way master
comes into existence on its first commit.
If you like, you can look at it in terms of underlying mechanism: when git creates a new commit, the steps used to update HEAD
go like this:1
HEAD
file.ref: refs/heads/master
? if yes, go to step 4.HEAD
and write new SHA-1 into HEAD
. Stop, we are done..git/refs/heads/master
, or from packed refs).As an interesting side note, when refs get packed, "active" ones (like whichever branch you're developing on, let's say devel
for instance) wind up in .git/packed-refs
, but are quickly updated with new values. Those new values go only in the .git/refs/heads/devel
file: the .git/packed-refs
file retains a refs/heads/devel
entry, but it's stale (and hence ignored). (You're not supposed to depend on this: external programs, such as shell scripts, should use git branch
or git update-ref
or git symbolic-ref
as appropriate, to read and write ref-names and SHA-1 values. Occasionally, though, it's useful to be able to go in and edit refs directly. Think of it as a modern-day equivalent of a hex editor for disk sectors. :-) )
1This all assumes you are not creating a merge commit. If you are in the middle of a merge, another file in the repository (.git/MERGE_HEAD
) supplies the extra merge parent IDs.
i have same issue and fixed - first of all use git add command after that use commit command finally use git branch to show your branched my git version 1.9
git add -A git commit -m "initialize" git branch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With