git branch is not showing all the branches

Viewed 112097

/opt/lampp/htdocs/drupal-8.4.0$ git branch

I have installed drupal in my system ,I want to switch to other branch but when used git branch is not showing other branches !

13 Answers

Execute git branch -av to show all remote and local branches.

It might be a possibility that you don't have those branches locally.

to pull all additional branches,

git fetch

it should be like this not like above

git fetch --all or git fetch <branch Name>

then you can use either checkout or branch to check if it shows

git checkout name-of-the-branch
git branch

Use git branch -a to see all branches in repo and then you can use git checkout branchname to checkout to respective branch

git branch --all

this git command will display all the branches.

This can happen if your repo has 0 commits. If you make a commit, your current branch will appear when you do: git branch.

Do a git fetch first in order to pull aditional branch info from the remote

I had a basic testing on this. The script: git branch -r is relying on remote reference of local git repository.

To get the remote branches, the best practice would be:

  1. Firstly, execute the script: git pull / git fetch /... to sync latest remote repository data into your local repository;

  2. Then execute the script: git remote prune origin to clean up those non-existed git branches in your local git repository;

  3. Finally, execute the script: git branch -r

do git branch -a it will give you all the branches in the remote. another option git fetch --all Then if you want to change or what operation you want to give you can do. example - if you want to change branch then git checkout <branch name from shown branches>

I am just updating, when I faced this and how it solved , may be helpful for someone in future.

I started repo using command $git init and later tried the command $git branch . But there was no output, later I added a new file and tried to commit. that time I got below error

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"
 

After providing above details command $git branch worked like a charm!!

  • Open git bash

  • Run the following command in the right git project folder:

    git config remote.origin.fetch "+refs/heads/:refs/remotes/origin/"

  • Fetch

Then you should be finally able to see the other branches.

Had the same issue, but none of the answers helped me.

My problem was when i made the git clone i added the parameter depth. This was my fault. So I cloned it again (without the depth parameter) and now i can see all branches.

I was facing similar type of issue.

So, I first added one file for example index.php in staging area using git add index.php and after that did the git commit -m some-text then I tried git branch and it worked.

Hence, You need to make at least one commit before you can see the other branch listed by the git branch command.

git branch -M [branch-name]

For instance:
git branch -M master

After this command, probably will should display:
* master

Related