Home > OS >  git branch not showing all branches
git branch not showing all branches

Time:06-02

I have a github repository with 2 branches named master and mobile. The mobile branch is the default branch on GitHub, and this is the branch I am pushing to from my local directory as well.

Whenever I have to push to remote, I have to enter the following command:

git push origin HEAD:mobile

I don't understand why I have to use the HEAD word for it to work. When I don't use it, I get a refspec error.

When I checked the branches using git branch, it only showed me * master. I don't understand why it is not able to see the mobile branch.

The output of git fetch is:

remote: Enumerating objects: 157, done.
remote: Counting objects: 100% (157/157), done.
remote: Compressing objects: 100% (111/111), done.
remote: Total 157 (delta 43), reused 154 (delta 42), pack-reused 0Receiving objects:  99% (156/157), 13.77 MiB | 9.01 MiB/s
Receiving objects: 100% (157/157), 14.22 MiB | 9.02 MiB/s, done.
Resolving deltas: 100% (43/43), done.
From https://github.com/myname/myreponame
 * [new branch]      master     -> origin/master

The output of git branch --all -vv is:

* master                f1881f6 cracker capture fixed
  remotes/origin/master ccad84b Create README.md
  remotes/origin/mobile  f1881f6 cracker capture fixed

CodePudding user response:

You have a remote mobile branch, but that doesn't automatically give you a local mobile branch. You have to make one if you want one. You forgot to do that. Thus all this time you've been working on master but pushing to the remote mobile.

To make a local mobile based on the remote mobile, say git switch mobile.

(Unfortunately that won't undo the damage you've done by pushing commits from your local master to the remote mobile. But it does explain completely the situation you've described in your question, namely why you didn't see any mobile listed and why you had to say git push origin HEAD:mobile.)

CodePudding user response:

Usually pushing to your main branch will only require to use 'git push' but if youre using the other one then should be git push origin (branch-name)

  •  Tags:  
  • git
  • Related