Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git is not showing all branches on local

I forked a repo from Github. On doing git remote -v it displays:

origin  https://github.com/myusername/moodle.git (fetch)
origin  https://github.com/myusername/moodle.git (push)
upstream    https://github.com/moodle/moodle.git (fetch)
upstream    https://github.com/moodle/moodle.git (push)

The moodle.git has about 10 branches, but the repo shows only 2 of them. On doing git branch -a (show all branches) I get:

  MOODLE_24_STABLE// just these two on local..how?
* master//
  origin/MOODLE_13_STABLE
  origin/MOODLE_14_STABLE
  origin/MOODLE_15_STABLE
  origin/MOODLE_16_STABLE
  origin/MOODLE_17_STABLE
  origin/MOODLE_18_STABLE
  origin/MOODLE_19_STABLE
  origin/MOODLE_20_STABLE
  origin/MOODLE_21_STABLE
  origin/MOODLE_22_STABLE
  origin/MOODLE_23_STABLE
  origin/MOODLE_24_STABLE
  origin/master
  upstream/MOODLE_13_STABLE
  upstream/MOODLE_14_STABLE
  upstream/MOODLE_15_STABLE
  upstream/MOODLE_16_STABLE
  upstream/MOODLE_17_STABLE
  upstream/MOODLE_18_STABLE
  upstream/MOODLE_19_STABLE
  upstream/MOODLE_20_STABLE
  upstream/MOODLE_21_STABLE
  upstream/MOODLE_22_STABLE
  upstream/MOODLE_23_STABLE
  upstream/MOODLE_24_STABLE
  upstream/master

How do I resolve my problem without any loss of data or any irregularities?

like image 745
xan Avatar asked Mar 30 '13 18:03

xan


People also ask

Does git store all branches locally?

Git stores all references under the . git/refs folder and branches are stored in the directory .

Why can't I see remote branches git?

First, double check that the branch has been actually pushed remotely, by using the command git ls-remote origin . If the new branch appears in the output, try and give the command git fetch : it should download the branch references from the remote repository.


2 Answers

Cloning a repo won't duplicate all the remote branches on the local repo: for a large remote repo with a lot of branches, that would pollute your local namespace with tons of branches.

I have a one-liner command in order to create local branches tracking all the remote branches of a remote repo, but this is usually not needed.
You only create a local branch tracking a remote one when needed.

git checkout -b aBranch --track origin/aBranch

# or, shorter:
$ git checkout --track origin/aBranch 
Branch aBranch set up to track remote branch refs/remotes/origin/aBranch.
Switched to a new branch "aBranch"  

# even shorter at the end of this answer.

Adding a --track allows for setting up the configuration to mark the start-point branch as "upstream" from the new branch.
This configuration will tell git to show the relationship between the two branches in git status and git branch -v.
Furthermore, it directs git pull without arguments to pull from the upstream when the new branch is checked out.


kostix mentions that --track is implied when forking a branch off a remote branch (unless branch.autosetupmerge is set to false)

This could be enough

git checkout aBranch

The exact explanation from git checkout man page is:

If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to:

$ git checkout -b <branch> --track <remote>/<branch
like image 181
VonC Avatar answered Sep 17 '22 17:09

VonC


Some times , if you havn't pulled the latest code, you wont be allowed to checkout the newly created branch.Because your changes are not in synch.

So first -pull the latest -checkout from newly created branch

like image 26
Grace Aloysius Avatar answered Sep 18 '22 17:09

Grace Aloysius