How to pull into not-the-current-branch?

git fetch -u origin master:master

Merge, update, and pull Git branches without using checkouts

git fetch -u <remote> <remoteBranch>:<localBranch>

The -u or --update-head-ok ensures that the command still works even if you have the given branch checked out, which otherwise gives the error:

fatal: Refusing to fetch into current branch refs/heads/master of non-bare repository

Leave a Comment