Checkout branch on different remote
If you just added the remote, you'll need to fetch
it so that Git knows which branches are available:
git fetch upstream master
After this you can do
git checkout upstream/master
without any issues.
In more concise way (I'm using git
2.28), you can say
git fetch upstream
and then
git checkout -b <branch_name> --guess
where the --guess
flag checks if a branch corresponding to <branch_name>
exists on any of the remotes and tracks the corresponding remote (docs here).
Just fetch the refs from the remote (this will fetch all branch, commit, refs etc for the upstream repo)
git fetch upstream
After this, checkout the needed branch (this creates a local copy of the branch)
git checkout -b <branchname> --track upstream/<branchname>
Now if you want to pull the changes in this branch in future, all you need to do is
git pull upstream <branchname>
As mentioned here, try doing an explicit fetch on the branch name:
git fetch upstream master:branch_name