I forked a github repository to my local github account and was working on the master branch for sometime. After this the original repository had a new branch created which is not there in my local forked repository. I normally update my local repository using "git pull upstream master". Now I want to work on the new branch created in the original repository and wondering how do I update my local repository to add the new branch.
-
`git fetch upstream`, `git checkout new-branch`? – Biffen Nov 21 '18 at 13:16
-
Possible duplicate of [After git update remote the new upstream branches are visible but not origin](https://stackoverflow.com/questions/25105784/after-git-update-remote-the-new-upstream-branches-are-visible-but-not-origin) – phd Nov 21 '18 at 16:34
-
https://stackoverflow.com/search?q=%5Bgit%5D+fetch+new+branch+from+upstream – phd Nov 21 '18 at 16:34
1 Answers
First git fetch upstream
to make sure you have a local copy of the most recent versions of the remote refs (branches). This is implicitly done each time you git pull upstream
anyway, but it can't hurt to check again before creating your local branch)
Then you can create your local instance of the branch with git checkout <branchName>
.
If you're unsure about the branch name, check it in the output of git branch -r
which lists the list of branches you updated with the earlier fetch
.
However, don't checkout the remote branch but the local counterpart.
For example : NOT git checkout remotes/origin/my_branch
which would end up in a detached HEAD state pointing to the commit this remote ref happened to point to. What you want to checkout is git checkout my_branch
if your config sets upstream automatically, adding the option --set-upstream-to=remotes/origin/my_branch
if it's not the case.

- 19,645
- 3
- 36
- 61