How to git checkout a remote branch named the same as a directory?

We have a remote branch named deploy for building and testing deploy scripts. Not surprisingly, the deploy scripts end up in a directory called deploy. Now that the directory deploy is in the branch master, when doing an initial clone it’s cumbersome to actually check out that branch.

$ git clone
$ cd mything
$ ls
deploy          extensions      installExtensions   src         tests
$ git branch -r | grep dep
$ git checkout deploy
$ git branch
* master
$ git checkout origin/deploy
Note: checking out 'origin/deploy'.

You are in 'detached HEAD' state. [SNIP]

At this point should I just create a local branch named deploy and set it to track the remote? Is there any syntax I can give git so it knows I want to checkout a remote branch, not a local path?

  • Git: How to keep local feature branch updated with changes made in dev?
  • With git, how do I remove a local copy of a remote branch? Or at least pull without merging?
  • Git in TFS - Remove branches after merging
  • Is there a way to configure Ivy to get dependencies from a branch without editing every dependency concerned?
  • How to fix TFS incorrect branching
  • List remote branches in Mercurial
  • Recommended git mode for Emacs
  • Git error: “Host Key Verification Failed” when connecting to remote repository
  • git rebase after pull
  • How to list files that have been created/removed between given commits
  • My xcode is showing two branches open at same time in source control
  • Can I create a custom protocol for git?
  • 2 Solutions collect form web for “How to git checkout a remote branch named the same as a directory?”

    You could simply create a new local branch that points to the remote branch using either of these commands (the latter will check it out immediately):

    git branch deploy origin/deploy
    git checkout -b deploy origin/deploy

    This will however not set up the tracking functionality that happens when Git automatically creates a branch for a remote branch. To do that you have to do the following:

    git branch -u origin/deploy

    As an alternative, you can do this all in a single command, which is the same what Git would automatically do:

    git checkout -b deploy --track origin/deploy

    My workaround for this is

    git checkout deploy --

    Git Baby is a git and github fan, let's start git clone.