-1

I have cloned a Github repository with the "--recursive" qualifier. I then checked out the latest branch in that repository.

Later, the author of the repository added a new branch. When I attempted to checkout that new branch with git checkout branch-name, git reported that the branch-name was unknown.

Is there a way to get the new branch-name without again cloning the repository?

user34299
  • 335
  • 1
  • 8
  • By clone, do you mean git clone or a fork? If a git clone, git fetch or simply git checkout your branch name will do the work. If you want to get the branch from upstream to your fork. Then follow the instructions on this page: https://note.tianhaoz.com/git-tricks/add-branch-from-upstream.html – Tianhao Zhou May 28 '19 at 15:16
  • 1
    Possible duplicate of [Git fetch remote branch](https://stackoverflow.com/questions/9537392/git-fetch-remote-branch) – phd May 28 '19 at 15:51
  • https://stackoverflow.com/search?q=%5Bgit%5D+update+local+branch – phd May 28 '19 at 15:51

3 Answers3

2

Use git fetch to retrieve new work done by other people including the newly added branch.

Fetching from a repository grabs all the new remote-tracking branches and tags without merging those changes into your own branches.

If you already have a local repository with a remote URL set up for the desired project, you can grab all the new information by using git fetch remotename

After fetching you can list all the branches including the newly added one by git branch -a

Then, you can select the required branch and checkout by git checkout requiredbranch-name

1

To get all the data (and also newly added branches) from remote repository which you don't have yet use the command git fetch.

Ivan R.
  • 1,722
  • 1
  • 11
  • 10
0

First fetch from your remote $ git fetch origin

You could list all branches with command git branch -a

And then, checkout required branch.

$ git fetch origin
$ git checkout --track origin/new_branch_1
Johnykutty
  • 9,871
  • 11
  • 50
  • 89