How to download a branch with git?

I have a project hosted on GitHub. I created a branch on one computer, then pushed my changes to github with

git push origin branch-name

Now I am on a different computer, and I want to download that branch. So I tried:

  • What command can I use to extract fields from this Git svn mirror commit messages?
  • git init, add, commit from a different directory
  • git: branches diverged; how to proceed?
  • Android studio - should the entire .idea directory be in git ignore?
  • What's the difference between HEAD^ and HEAD~ in Git?
  • Is it possible to git reset as a new commit?
  • git pull origin branch-name

    …but all this did was overwrite my master branch with the changes in my new branch.

    What do I need to do to properly pull my remote branch?

  • I can't see my remote branch
  • git hook script output is added with annoying “[K” postfix
  • Git pull until there is something to pull
  • Swap git submodule with own fork
  • Where is .gitignore_global saved on OS X?
  • Can't checkout local branch using git plugin
  • 5 Solutions collect form web for “How to download a branch with git?”

    Thanks to a related question, I found out that that I need to “checkout” the remote branch as a new local branch, and specify a new local branch name.

    git checkout -b newlocalbranchname origin/branch-name

    Or you can do:

    git checkout -t origin/branch-name

    The latter will create a branch that is also set to track the remote branch.

    Update: It’s been 5 years since I originally posted this question. I’ve learned a lot and git has improved since then. My usual workflow is a little different now.

    If I want to fetch the remote branches, I simply run:

    git pull

    This will fetch all of the remote branches and merge the current branch. It will display an output that looks something like this:

       dbd07ad..4316d29  master     -> origin/master
     * [new branch]      production -> origin/production
     * [new branch]      my-bugfix-branch -> origin/my-bugfix-branch
    First, rewinding head to replay your work on top of it...
    Fast-forwarded master to 4316d296c55ac2e13992a22161fc327944bcf5b8.

    Now git knows about my new my-bugfix-branch. To switch to this branch, I can simply run:

    git checkout my-bugfix-branch

    Normally, I would need to create the branch before I could check it out, but in newer versions of git, it’s smart enough to know that you want to checkout a local copy of this remote branch.

    For any Git newbies like me, here are some steps you could follow to download a remote repository, and then switch to the branch that you want to view. They probably abuse Git in some way, but it did the job for me! 🙂

    Clone the repository you want to download the code for (in this example I’ve picked the LRResty project on Github):

    $ git clone
    $ cd LRResty

    Check what branch you are using at this point (it should be the master branch):

    $ git branch    
    * master

    Check out the branch you want, in my case it is called ‘arcified’:

     $ git checkout -b arcified origin/arcified
     Branch arcified set up to track remote branch arcified from origin.
     Switched to a new branch 'arcified'

    Confirm you are now using the branch you wanted:

    $ git branch    
    * arcified

    If you want to update the code again later, run git pull:

    $ git pull
    Already up-to-date.

    You could use git remote like:

    git fetch origin

    and then setup a local branch to track the remote branch like below:

    git branch --track [local-branch-name] origin/remote-branch-name

    You would now have the contents of the remote github branch in local-branch-name.

    You could switch to that local-branch-name and start work:

    git checkout [local-branch-name]

    Git clone and cd in the repo name:

    $ git clone
    Cloning into 'iOS-AppleWach'...
    $ cd iOS-AppleWach

    Switch to the branch (a GitHub page) that I want:

    $ git checkout -b gh-pages origin/gh-pages
    Branch gh-pages set up to track remote branch gh-pages from origin.
    Switched to a new branch 'gh-pages'

    And pull the branch:

    $ git pull
    Already up-to-date.


    $ ls
    index.html      params.json     stylesheets

    Create a new directory, and do a clone instead.

    git clone (address of origin) (name of branch)

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