How do I pull a remote branch in Git and track it locally?

The remote repository has several branches like origin/daves_branch:

$ git branch -r
origin/HEAD -> origin/master  
origin/daves_branch  
origin/master

I want to switch to daves_branch in my local repo so it tracks origin/daves_branch. I tried:

git fetch origin daves_branch  
git checkout daves_branch

Is this the correct way to git pull a remote branch and set it up for tracking locally? Or is there a better approach to ensure it pulls future updates smoothly?

You’re almost there! If daves_branch doesn’t already exist locally, just run:

git checkout -b daves_branch origin/daves_branch

This creates a local branch named daves_branch and sets it to track the remote one. After that, git pull will automatically pull changes from origin/daves_branch.