Search code examples
gitgithubrepositoryclone

git - how do I get the name of new branches?


I have been using git for a while and am comfortable with most of the operations, push, pulls, merges, branches, forks, etc.

My question is about "When I clone a repository, I get a copy of all of the code, including all branches" which I think is true.

However, what happens when someone else makes a branch and then pushes that branch to github - just the unmerged branch that is. Will I not "get" this new branch unless I specifically git pull it by name of branch? That is how it seems. If I started from scratch and cloned the whole repository again, would that mean I would get the new branch? My key question is - how do I know what other branches exist. That is, although I may personally "know" the branch name from the developer, what if I don't - how does my "local" git clone know about new branch names? Is it when I git pull origin master that I get the names of new branches and then I have to git pull origin [new_branch_name] using new_branch_name from the list that master has?

How do I know the names of new branches on the remote?


Solution

  • git fetch will download any updates for your repo, including new branches.

    The output for the fetch command will indicate that new branches are being/have been downloaded.

    You can then use git branch -r to see the list of remote branches that are available. You will not see the new branches in this output unless you have done the fetch command first.