Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git shows no branches

Tags:

git

I've created a bare repository than cloned it. When I do git branch -a nothing is showed. How come I don't even see the default master branch? Although git bash shows the following:

/some/path/project (master)
like image 502
Max Koretskyi Avatar asked Nov 02 '13 08:11

Max Koretskyi


People also ask

Can't see all the branches git?

To see local branches, use the git branch command. The git branch command lets you see a list of all the branches stored in your local version of a repository. To see the remote branches associated with your repository, you need to append the -r flag to the end of the git branch command.

What is no branch in git?

The “no branch” state is called a detached HEAD. It is called this because the HEAD ref is not attached to any branch, instead it is pointing directly at a commit. To attach HEAD to a branch that points to the current HEAD commit, use git checkout -b branchname .

Why git branch is empty?

If you run git branch in the current directory then it will return no branches as the repository is empty and the master branch will be created with the first commit.


2 Answers

You have probably cloned an empty repository, there is nothing for the master branch to point to.

  • A branch points to a commit
  • A commit points to a tree
  • A tree lists some blobs or other trees
like image 108
Emil Davtyan Avatar answered Oct 24 '22 00:10

Emil Davtyan


For the repository to show branches, you first need to add the files and commit. Use git add -a for adding all files or use git add <file_name> to add a particular file. After adding the file, use git commit -a to commit all added files. It will take you to the vim editor where you must write the commit message, and exit the editor after saving. Once this is done, you will be able to see the branch master. To confirm type git branch and it will now show you all the branches. Now, you can add other branches by using the command git branch <new_branch_name>.

like image 38
Gaurav Saxena Avatar answered Oct 23 '22 22:10

Gaurav Saxena