0

I am trying to learn git and its workflow & I want to ask if how do I fetch all the branches in git after cloning a project repo in github?

So my main focus is to learn collaborating with git and I am cloning a project repo in github with 2 branches in my main project.

this is my main repo's git branch result

enter image description here

and this is in my clone folder

enter image description here

I didn't get all the repository there , you see ?

TheBAST
  • 2,680
  • 10
  • 40
  • 68

4 Answers4

1

You can use

git fetch --all

And then you check if it work or not

git branch -a 
Hay Trần
  • 564
  • 4
  • 22
1

You cloned the whole repository.

All the branches are there.

You can confirm this with git branch --all.

Go on, check out basic-feature. It will work.

tymtam
  • 31,798
  • 8
  • 86
  • 126
1

The simple (but subtly wrong, in multiple ways) answer is that you already have all the branches.

I am trying to learn git and its workflow & I want to ask if how do I fetch all the branches in git after cloning a project repo in github?

As tymtam said, you can just git checkout a name like basic-feature and suddenly it's there.

This bit of magic is brought to you by what Git calls DWIM mode, where DWIM stands for Do What I Mean (as opposed to what you said). If you ask Git to check out a branch name that you don't have yet—such as basic-feature—your Git will proceed to search through a second set of names, which are your Git's remote-tracking names. On finding an appropriate match, git checkout will actually create the name for you, right on the spot.

To list your repository's remote-tracking names, use:

git branch --list --remote

which you can abbreviate to just:

git branch -r

(Note: if your Git is extremely old, it may have only the short form options.)

A remote-tracking name is a name like origin/master or origin/basic-feature. When you clone some other repository, you give your Git a short name for that other repository. You can choose a name, but the default one is origin. This is called a remote. The short name origin stands in for the longer URL that you entered (e.g., https://github.com/path/to/repo.git).

When your Git calls up the other Git, your Git gets, from the other Git, a list of all of its branch names. Your Git then copies those names to your origin/* names—or some other prefix if you chose some other name instead of origin. These are your remote-tracking names, which remember their Git's branch names. (Git itself calls them remote-tracking branch names, but I find the extra word branch in here unhelpful. These names act sort of like branch names, but enough different that I prefer to leave out the word branch now.)

There is a problem with Git's nomenclature here, because the word branch itself has multiple different meanings. See What exactly do we mean by "branch"? Sometimes we mean a branch name, sometimes we mean a remote-tracking name, and sometimes we mean some collection of commits, probably found by using one of those names. You must infer from context which of these someone means, if they just say "a branch".

Note that while git fetch has this --all option, it means all remotes. You can list out which remote names you have—likely just origin—using:

git remote

If you have more than one, git fetch --all will invoke git fetch on each one. If, as usual, you only have one, git fetch --all will invoke git fetch on all one of them, and hence not do anything different from git fetch without --all.

torek
  • 448,244
  • 59
  • 642
  • 775
0
git fetch --all

or

git remote update

Remind that, fetch will not create or update local branches (which track remote branches); if you want to update your local branches you still need to pull every branch.

If you want to list all remote branches:

git branch -a 

To update local branches which track remote branches:

git pull --all
Noor A Shuvo
  • 2,639
  • 3
  • 23
  • 48
  • Again, `--all` is not necessary. This option fetches from all *remotes*. You already get all branches by default, from *one* remote. If you have only one remote—as the OP does—fetching one remote *is* fetching from all. – torek Nov 21 '19 at 06:33