How to checkout a remote branch in Git?

Someone pushed a “new feature” branch to the shared repo:

git push -u new_feature_branch

Now, I would like to create a copy of this branch on my local machine in order to test the new feature.

  • git rm - fatal: pathspec did not match any files
  • github workflow - fatal: not a git repository (or any of the parent directories): .git
  • How to enter command with password for git pull?
  • **Visual Studio 2015, should I commit Project.sln.ide\* files into git?
  • GitHub for Mac: Can't commit and sync or just commit because I have to add files before
  • Selective git ignore by remote?
  • What would be the easiest way to do this? (Do I need to fetch / pull before checkout?)

  • How can I find all the commits that have more than one parent in a Git repository?
  • How to make “git push” include tags within a branch?
  • Visual Studio 2013 Github commit deadlock
  • Programmatically swap last two commits
  • git maintaining 2 versions of the same project, with different users on each
  • Git: updating remote branch information
  • 4 Solutions collect form web for “How to checkout a remote branch in Git?”

    I generally find it unnecessary to use git fetch. git pull is sufficient. git pull will synchronize your repository with the remote. The new_feature_branch will then be available.

    git checkout new_feature_branch will notice the branch in origin and create a new local tracking branch for you and switch to that branch.

    git pull
    git checkout new_feature_branch

    The simplest way to do this is:

    git fetch
    git checkout -t origin/new_feature_branch

    This is only done initially. From now on you can continue working with the branch as you do for the others you use.

    You need to fetch upstream changes so your local repository includes the relevant objects (git fetch --all or git fetch <remote>).

    Afterwards you can perform a checkout using git checkout <branch> (if you like to do it explicitly, you can type git checkout -b <branch> <remote>/<branch>; the local name doesn’t have to be the same as the remote). If you don’t already have a local branch of that name, it will checkout the remote branch and track it.

    As an alternative to this, you can use git pull <remote> <branch>, but this will – with default settings – merge the remote branch into your current, which is probably not what you want.

    git fetch && git checkout new_feature_branch
    Git Baby is a git and github fan, let's start git clone.