How do I check out a remote Git branch?











up vote
5600
down vote

favorite
1471












Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r.



Now I'm trying to check out the remote test branch.



I've tried:




  • git checkout test which does nothing


  • git checkout origin/test gives * (no branch). Which is confusing. How can I be on "no branch"?



How do I check out a remote Git branch?










share|improve this question























  • 7




    @inger But it does not include the possibility to rename the new local branch (if you want to --set-upstream later on and keep naming consistency)
    – fachexot
    Feb 1 '14 at 12:43






  • 13




    I think this thread is unhelpful. Nothing seems to work, the original question seems to have been lost in many of the answers. I have read every word, tried everything below, and have no idea how to do what the OP wants to do.
    – Tony Ennis
    Aug 26 '14 at 0:16






  • 5




    Git commands are not intuitive to begin with, add the changes introduced with recent versions to the mix and you have this page...
    – Christophe Roussy
    Jan 12 '16 at 17:41








  • 8




    I feel like I'm taking crazy pills. I'm trying to checkout a branch from an upstream, not just origin, and every recommended answer doesn't do anything remotely helpful (pun-intended). EDIT - excuse me, the multitude of suggestions contained in the top 2 answers were useless; 3rd one (git branch test origin/test) is what works. Glad the top 2 have 20x the number of votes...
    – dwanderson
    Mar 9 '17 at 16:35








  • 2




    Maybe you have a file named 'test' in your work tree, see stackoverflow.com/a/45006389/792416 for detail.
    – oldman
    Jul 10 '17 at 7:50















up vote
5600
down vote

favorite
1471












Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r.



Now I'm trying to check out the remote test branch.



I've tried:




  • git checkout test which does nothing


  • git checkout origin/test gives * (no branch). Which is confusing. How can I be on "no branch"?



How do I check out a remote Git branch?










share|improve this question























  • 7




    @inger But it does not include the possibility to rename the new local branch (if you want to --set-upstream later on and keep naming consistency)
    – fachexot
    Feb 1 '14 at 12:43






  • 13




    I think this thread is unhelpful. Nothing seems to work, the original question seems to have been lost in many of the answers. I have read every word, tried everything below, and have no idea how to do what the OP wants to do.
    – Tony Ennis
    Aug 26 '14 at 0:16






  • 5




    Git commands are not intuitive to begin with, add the changes introduced with recent versions to the mix and you have this page...
    – Christophe Roussy
    Jan 12 '16 at 17:41








  • 8




    I feel like I'm taking crazy pills. I'm trying to checkout a branch from an upstream, not just origin, and every recommended answer doesn't do anything remotely helpful (pun-intended). EDIT - excuse me, the multitude of suggestions contained in the top 2 answers were useless; 3rd one (git branch test origin/test) is what works. Glad the top 2 have 20x the number of votes...
    – dwanderson
    Mar 9 '17 at 16:35








  • 2




    Maybe you have a file named 'test' in your work tree, see stackoverflow.com/a/45006389/792416 for detail.
    – oldman
    Jul 10 '17 at 7:50













up vote
5600
down vote

favorite
1471









up vote
5600
down vote

favorite
1471






1471





Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r.



Now I'm trying to check out the remote test branch.



I've tried:




  • git checkout test which does nothing


  • git checkout origin/test gives * (no branch). Which is confusing. How can I be on "no branch"?



How do I check out a remote Git branch?










share|improve this question















Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r.



Now I'm trying to check out the remote test branch.



I've tried:




  • git checkout test which does nothing


  • git checkout origin/test gives * (no branch). Which is confusing. How can I be on "no branch"?



How do I check out a remote Git branch?







git git-checkout remote-branch






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 21 '17 at 11:15









Peter Mortensen

13.3k1983111




13.3k1983111










asked Nov 23 '09 at 14:23









Juri Glass

30.3k72843




30.3k72843












  • 7




    @inger But it does not include the possibility to rename the new local branch (if you want to --set-upstream later on and keep naming consistency)
    – fachexot
    Feb 1 '14 at 12:43






  • 13




    I think this thread is unhelpful. Nothing seems to work, the original question seems to have been lost in many of the answers. I have read every word, tried everything below, and have no idea how to do what the OP wants to do.
    – Tony Ennis
    Aug 26 '14 at 0:16






  • 5




    Git commands are not intuitive to begin with, add the changes introduced with recent versions to the mix and you have this page...
    – Christophe Roussy
    Jan 12 '16 at 17:41








  • 8




    I feel like I'm taking crazy pills. I'm trying to checkout a branch from an upstream, not just origin, and every recommended answer doesn't do anything remotely helpful (pun-intended). EDIT - excuse me, the multitude of suggestions contained in the top 2 answers were useless; 3rd one (git branch test origin/test) is what works. Glad the top 2 have 20x the number of votes...
    – dwanderson
    Mar 9 '17 at 16:35








  • 2




    Maybe you have a file named 'test' in your work tree, see stackoverflow.com/a/45006389/792416 for detail.
    – oldman
    Jul 10 '17 at 7:50














  • 7




    @inger But it does not include the possibility to rename the new local branch (if you want to --set-upstream later on and keep naming consistency)
    – fachexot
    Feb 1 '14 at 12:43






  • 13




    I think this thread is unhelpful. Nothing seems to work, the original question seems to have been lost in many of the answers. I have read every word, tried everything below, and have no idea how to do what the OP wants to do.
    – Tony Ennis
    Aug 26 '14 at 0:16






  • 5




    Git commands are not intuitive to begin with, add the changes introduced with recent versions to the mix and you have this page...
    – Christophe Roussy
    Jan 12 '16 at 17:41








  • 8




    I feel like I'm taking crazy pills. I'm trying to checkout a branch from an upstream, not just origin, and every recommended answer doesn't do anything remotely helpful (pun-intended). EDIT - excuse me, the multitude of suggestions contained in the top 2 answers were useless; 3rd one (git branch test origin/test) is what works. Glad the top 2 have 20x the number of votes...
    – dwanderson
    Mar 9 '17 at 16:35








  • 2




    Maybe you have a file named 'test' in your work tree, see stackoverflow.com/a/45006389/792416 for detail.
    – oldman
    Jul 10 '17 at 7:50








7




7




@inger But it does not include the possibility to rename the new local branch (if you want to --set-upstream later on and keep naming consistency)
– fachexot
Feb 1 '14 at 12:43




@inger But it does not include the possibility to rename the new local branch (if you want to --set-upstream later on and keep naming consistency)
– fachexot
Feb 1 '14 at 12:43




13




13




I think this thread is unhelpful. Nothing seems to work, the original question seems to have been lost in many of the answers. I have read every word, tried everything below, and have no idea how to do what the OP wants to do.
– Tony Ennis
Aug 26 '14 at 0:16




I think this thread is unhelpful. Nothing seems to work, the original question seems to have been lost in many of the answers. I have read every word, tried everything below, and have no idea how to do what the OP wants to do.
– Tony Ennis
Aug 26 '14 at 0:16




5




5




Git commands are not intuitive to begin with, add the changes introduced with recent versions to the mix and you have this page...
– Christophe Roussy
Jan 12 '16 at 17:41






Git commands are not intuitive to begin with, add the changes introduced with recent versions to the mix and you have this page...
– Christophe Roussy
Jan 12 '16 at 17:41






8




8




I feel like I'm taking crazy pills. I'm trying to checkout a branch from an upstream, not just origin, and every recommended answer doesn't do anything remotely helpful (pun-intended). EDIT - excuse me, the multitude of suggestions contained in the top 2 answers were useless; 3rd one (git branch test origin/test) is what works. Glad the top 2 have 20x the number of votes...
– dwanderson
Mar 9 '17 at 16:35






I feel like I'm taking crazy pills. I'm trying to checkout a branch from an upstream, not just origin, and every recommended answer doesn't do anything remotely helpful (pun-intended). EDIT - excuse me, the multitude of suggestions contained in the top 2 answers were useless; 3rd one (git branch test origin/test) is what works. Glad the top 2 have 20x the number of votes...
– dwanderson
Mar 9 '17 at 16:35






2




2




Maybe you have a file named 'test' in your work tree, see stackoverflow.com/a/45006389/792416 for detail.
– oldman
Jul 10 '17 at 7:50




Maybe you have a file named 'test' in your work tree, see stackoverflow.com/a/45006389/792416 for detail.
– oldman
Jul 10 '17 at 7:50












26 Answers
26






active

oldest

votes

















up vote
7752
down vote



accepted










Update



Jakub's answer actually improves on this. With Git versions ≥ 1.6.6, with only one remote, you can just do:



git fetch
git checkout test


As user masukomi points out in a comment, git checkout test will NOT work in modern git if you have multiple remotes. In this case use



git checkout -b test <name of remote>/test


Old Answer



Before you can start working locally on a remote branch, you need to fetch it as called out in answers below.



To fetch a branch, you simply need to:



git fetch origin


This will fetch all of the remote branches for you. You can see the branches available for checkout with:



git branch -v -a


With the remote branches in hand, you now need to check out the branch you are interested in, giving you a local working copy:



git checkout -b test origin/test





share|improve this answer



















  • 354




    To expand on this: git doesn't allow you to work on someone else's branches. You can only work on your own. So if you want to add to someone else's branch, you need to create your own "copy" of that branch, which is what the above command does (well, it creates your branch and checks it out, too).
    – Dan Moulding
    Nov 23 '09 at 15:24






  • 130




    If it's a new remote branch you may need to git fetch before doing this so that git is aware of origin/test
    – Neil Sarkar
    Nov 4 '11 at 14:38








  • 53




    ...and you would do this with git fetch origin test
    – Andrew
    Jan 22 '12 at 23:24






  • 19




    Error: "git checkout: updating paths is incompatible with switching branches. Did you intend to checkout origin/test which can not be resolved as commit?"
    – Xeoncross
    Sep 11 '12 at 20:35








  • 75




    git checkout test will NOT work in modern git if you have multiple remotes which have the same branch name. It can't know which one to use.
    – masukomi
    Sep 16 '14 at 15:34


















up vote
1122
down vote













Sidenote: With modern Git (>= 1.6.6), you are able to use just



git checkout test


(note that it is 'test' not 'origin/test') to perform magical DWIM-mery and create local branch 'test' for you, for which upstream would be remote-tracking branch 'origin/test'.





The * (no branch) in git branch output means that you are on unnamed branch, in so called "detached HEAD" state (HEAD points directly to commit, and is not symbolic reference to some local branch). If you made some commits on this unnamed branch, you can always create local branch off current commit:



git checkout -b test HEAD





share|improve this answer



















  • 29




    Unsurprising, but this version has been released in the last few years - knowing this syntax can save a lot of time since there's still a lot of old documentation and comment threads floating around that suggest the older method for doing this.
    – Curtis
    Apr 16 '12 at 13:24






  • 10




    "modern git"--for the record, (approx) what version are you referring to? Sometimes we have to work on systems running older distros.
    – Craig McQueen
    Aug 28 '12 at 2:30








  • 5




    "modern git" in this context is git 1.6.6
    – Bobby Norton
    Mar 19 '13 at 20:29








  • 10




    @aidan If you get a response like error: pathspec 'branch_name' did not match any file(s) known to git. then you should do a git fetch first.
    – Dennis
    Oct 18 '13 at 0:40






  • 4




    Using git version 1.8.3.msysgit.0 and this doesn't work for me - did not match any file(s) known to git - I've done many git fetches
    – PandaWood
    Dec 3 '13 at 23:59


















up vote
499
down vote













In this case, you probably want to create a local test branch which is tracking the remote test branch:



$ git branch test origin/test


In earlier versions of git, you needed an explicit --track option, but that is the default now when you are branching off a remote branch.






share|improve this answer



















  • 12




    This will create a local branch without switching to it.
    – Alex.Designworks
    Oct 16 '13 at 7:20






  • 2




    Though I got fatal: Ambiguous object name: 'origin/dev' - where a branch 'dev' on origin most definitely exists - but I'd accidentally created a branch called "origin/dev" on my machine (in my previous stupid attempts to get this right, no doubt) ... ouch
    – PandaWood
    Dec 4 '13 at 0:04








  • 1




    This has been giving me the error error: failed to push some refs to hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. Check out this branch and merge the remote changes hint: (e.g. 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    – pal4life
    Jun 18 '14 at 20:01










  • git branch test works for me
    – Isaac Pak
    Feb 17 '17 at 15:27




















up vote
415
down vote














Accepted answer not working for you?



While the first and selected answer is technically correct, there's the possibility you have not yet retrieved all objects and refs from the remote repository. If that is the case, you'll receive the following error:



$ git checkout -b remote_branch origin/remote_branch



fatal: git checkout: updating paths is incompatible with switching branches.

Did you intend to checkout 'origin/remote_branch' which can not be resolved as commit?




Solution



If you receive this message, you must first do a git fetch origin where origin is the name of the remote repository prior to running git checkout remote_branch. Here's a full example with responses:



$ git fetch origin
remote: Counting objects: 140, done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 69 (delta 36), reused 66 (delta 33)
Unpacking objects: 100% (69/69), done.
From https://github.com/githubuser/repo-name
e6ef1e0..5029161 develop -> origin/develop
* [new branch] demo -> origin/demo
d80f8d7..359eab0 master -> origin/master

$ git checkout demo
Branch demo set up to track remote branch demo from origin.
Switched to a new branch 'demo'


As you can see, running git fetch origin retrieved any remote branches we were not yet setup to track on our local machine. From there, since we now have a ref to the remote branch, we can simply run git checkout remote_branch and we'll gain the benefits of remote tracking.






share|improve this answer



















  • 2




    I'll add a note if you have a separate branch locally: Make sure you have associated this with the remote repo using 'git remote add origin [the_path_to_your_repo/repo_name.git]' . Then use 'git fetch origin' where 'origin' means the origin repository you have made the association with.
    – elliotrock
    Feb 2 '15 at 5:51










  • git checkout -b newbranch also works great for 1-step create and checkout a new branch based on the current branch.
    – Linus
    May 19 '16 at 13:41






  • 2




    I think this is the most up-to-date (it keeps $@#!ing changing!). Git 2.5.5 I found the only way to actually see the remote branches was git ls-remote and the only way to actually use one is git checkout -b [branch] --track [remote/branch]...and that's after git pull [remote] [branch] worked. I.e., it actually pulled the whole branch, but still wouldn't list it.
    – delicateLatticeworkFever
    May 26 '16 at 12:51












  • and when this answer doesn't work either, see this one.
    – eis
    Jan 16 at 12:48


















up vote
197
down vote













I tried the above solution, but it didn't work. Try this, it works:



git fetch origin 'remote_branch':'local_branch_name'


This will fetch the remote branch and create a new local branch (if not exists already) with name local_branch_name and track the remote one in it.






share|improve this answer



















  • 27




    This worked for me when neither git fetch origin or git remote update created local branches. I'm not sure why.
    – Godsmith
    Sep 11 '14 at 8:45






  • 4




    This was the most direct way to accomplish what I needed which was to use a remote branch (not master) to create a new branch.
    – Roralee
    Nov 13 '15 at 23:15






  • 7




    Worked seamlessly, especially when having cloned a single branch from a remote with multiple branches.
    – Alex C
    Oct 17 '16 at 10:19






  • 7




    this worked for me too, where accepted answers and other high voted didn't. My git version is 2.5.0
    – pdepmcp
    Feb 17 '17 at 12:46






  • 4




    Does anyone have any idea why this works when everything else doesn't? (I'm on git 2.13.0)
    – Nathan Arthur
    Jun 19 '17 at 18:43




















up vote
103
down vote













This will DWIM for a remote not named origin (documentation):



$ git checkout -t remote_name/remote_branch


To add a new remote, you will need to do the following first:



$ git remote add remote_name location_of_remote
$ git fetch remote_name


The first tells Git the remote exists, the second gets the commits.






share|improve this answer






























    up vote
    94
    down vote













    Use:



    git checkout -b <BRANCH-NAME> <REMOTE-NAME>/<BRANCH-NAME>


    Other answers do not work with modern Git in my benign case. You might need to pull first if the remote branch is new, but I haven't checked that case.






    share|improve this answer



















    • 2




      Do you realize that this is an extract of this answer
      – Thomas Ayoub
      Feb 21 '16 at 11:03






    • 12




      Looking at it now, they do overlap. Only mine is succinct and tells you what to do rather than tell a story. I assume it can be more useful therefore, especially for nowadays git versions. You can downvote it if you think it is a bad answer.
      – matanster
      Feb 21 '16 at 11:34




















    up vote
    60
    down vote













    OK, the answer is easy... You basically see the branch, but you don't have a local copy yet!...



    You need to fetch the branch...



    You can simply fetch and then checkout to the branch, use the one line command below to do that:



    git fetch && git checkout test


    I also created the image below for you to share the differences, look at how fetch works and also how it's different to pull:



    git fetch






    share|improve this answer



















    • 5




      Great picture, thanks
      – developer
      Sep 8 '17 at 10:05










    • Does not work if there is no local branch test
      – Dmitri Zaitsev
      Apr 25 at 3:26










    • @DmitriZaitsev yes, it will work, if the remote branch is there, and you do fetch, you will get the branch locally... git fetch && git checkout test..So this works, unless there is no remote branch, but the question saying there is already a remote branch there...
      – Alireza
      Apr 25 at 5:13










    • The way I see the question, test looks like a new branch, so it is not likely to be present locally. Otherwise you could pull it easier with single git pull command.
      – Dmitri Zaitsev
      Apr 25 at 12:51










    • @DmitriZaitsev, yes, that's why I said git fetch, that check for remote branches which just created, pull can bring other unwanted stuffs in, but fetch makes all branches available if you already have the repo locally...
      – Alireza
      Apr 25 at 13:36


















    up vote
    47
    down vote













    To clone a Git repository, do:



    git clone <either ssh url /http url>


    The above command checks out all of the branches, but only the master branch will be initialized. If you want to checkout the other branches, do:



    git checkout -t origin/future_branch (for example)


    This command checks out the remote branch, and your local branch name will be same as the remote branch.



    If you want to override your local branch name on checkout:



    git checkout -t -b enhancement origin/future_branch


    Now your local branch name is enhancement, but your remote branch name is future_branch.



    Documentation






    share|improve this answer























    • git clone <either ssh url /http url> - works perfectly for me
      – Kmeixner
      Dec 16 '14 at 16:56










    • Yes you are correct. Thanks for your information, I will update it very soon @warvariuc
      – Madhan Ayyasamy
      Jan 8 '15 at 10:45










    • If the remote has no master, this is not going to work.
      – polkovnikov.ph
      Sep 27 '16 at 16:47


















    up vote
    30
    down vote













    You can try



    git fetch remote
    git checkout --track -b local_branch_name origin/branch_name


    or



    git fetch
    git checkout -b local_branch_name origin/branch_name





    share|improve this answer



















    • 2




      FYI, --track is no longer needed in newer versions of git, because it's set by default, as explained in this earlier answer.
      – user456814
      Jun 21 '14 at 18:03


















    up vote
    27
    down vote













    First, you need to do:



    git fetch # If you don't know about branch name



    git fetch origin branch_name


    Second, you can check out remote branch into your local by:



    git checkout -b branch_name origin/branch_name


    -b will create new branch in specified name from your selected remote branch.






    share|improve this answer























    • I dont understand -b. If you can do "git checkout master" why cant you do "git checkout origin/test"?
      – John Little
      Jan 23 at 18:16










    • -b for new branch which is from origin/master
      – Mohideen ibn Mohammed
      Jan 24 at 1:13


















    up vote
    24
    down vote













    Commands



    git fetch --all
    git checkout -b <ur_new_local_branch_name> origin/<Remote_Branch_Name>


    are equal to



     git fetch --all


    and then



     git checkout -b fixes_for_dev origin/development


    Both will create a latest fixes_for_dev from development






    share|improve this answer






























      up vote
      23
      down vote













      I use the following command:



      git checkout --track origin/other_remote_branch





      share|improve this answer



















      • 8




        This answer would be a lot more useful if you explain why you are using it this way. i.e. why someone should use '--track' and so on...
        – Matt Friedman
        Nov 20 '17 at 3:19


















      up vote
      22
      down vote













      If the branch is on something other than the origin remote I like to do the following:



      $ git fetch
      $ git checkout -b second/next upstream/next


      This will checkout the next branch on the upstream remote in to a local branch called second/next. Which means if you already have a local branch named next it will not conflict.



      $ git branch -a
      * second/next
      remotes/origin/next
      remotes/upstream/next





      share|improve this answer






























        up vote
        15
        down vote













        git fetch && git checkout your-branch-name






        share|improve this answer




























          up vote
          14
          down vote













          git branch -r says the object name is invalid, because that branch name isn't in Git's local branch list. Update your local branch list from origin with:



          git remote update


          And then try checking out your remote branch again.



          This worked for me.



          I believe git fetch pulls in all remote branches, which is not what the original poster wanted.






          share|improve this answer



















          • 2




            FYI, git remote update will also fetch all remote branches.
            – user456814
            Jun 21 '14 at 17:59




















          up vote
          11
          down vote













          none of these answers worked for me. this worked:



          git checkout -b feature/branch remotes/origin/feature/branch






          share|improve this answer





















          • thanks. I was wondering if I had to use the full path (remotes/origin/feature/branch) that I saw in git when calling git branch -a command, but I wasn't for sure, so I just used git checkout -b apps/FEATURE/branch origin/apps/FEATURE/branch and it appeared to work. Message: Branch 'apps/FEATURE/branch' set up to track remote branch 'apps/FEATURE/epicBranch' from 'origin'. Switched to a new branch 'apps/FEATURE/branch'
            – Chris22
            Jul 27 at 15:41




















          up vote
          10
          down vote













          The git remote show <origin name> command will list all branches (including un-tracked branches). Then you can find the remote branch name that you need to fetch.



          Example:



          $ git remote show origin


          Use these steps to fetch remote branches:



          git fetch <origin name> <remote branch name>:<local branch name>
          git checkout <local branch name > (local branch name should the name that you given fetching)


          Example:



          $ git fetch origin test:test
          $ git checkout test





          share|improve this answer























          • @hallski answered not working 2.15.1 versions but i have reduce .git file weigth clone only 1 branch and filter history with --depth flag. for example $ git clone -b release --single-branch --depth 5 https://github.com/user/repo.git Wron't information $ git remote show originthis does not listed all remote branch with single branch cloned repositories.
            – Qh0stM4N
            Jan 30 at 13:52


















          up vote
          7
          down vote













          Other guys and gals give the solutions, but maybe I can tell you why.




          git checkout test which does nothing




          Does nothing doesn't equal doesn't work, so I guess when you type 'git checkout test' in your terminal and press enter key, no message appears and no error occurs. Am I right?



          If the answer is 'yes', I can tell you the cause.



          The cause is that there is a file (or folder) named 'test' in your work tree.



          When git checkout xxx parsed,




          1. Git looks on xxx as a branch name at first, but there isn't any branch named test.

          2. Then Git thinks xxx is a path, and fortunately (or unfortunately), there is a file named test. So git checkout xxx means discard any modification in xxx file.

          3. If there isn't file named xxx either, then Git will try to create the xxx according to some rules. One of the rules is create a branch named xxx if remotes/origin/xxx exists.






          share|improve this answer






























            up vote
            6
            down vote













            You can start tracking all remote branches with the following Bash script:



            #!/bin/bash
            git fetch --all
            for branch in `git branch -r --format="%(refname:short)" | sed 's/origin///'`
            do git branch -f --track "$branch" "origin/$branch"
            done


            Here is also a single-line version:



            git fetch --all; for branch in `git branch -r --format="%(refname:short)" | sed 's/origin///'`; do git branch --track "$branch" "origin/$branch" ; done ;





            share|improve this answer






























              up vote
              5
              down vote













              To get newly created branches



              git fetch


              To switch into another branch



              git checkout BranchName





              share|improve this answer






























                up vote
                4
                down vote













                Simply run git checkout with the name of the remote branch. Git will automatically create a local branch that tracks the remote one:



                git fetch
                git checkout test


                However, if that branch name is found in more than one remote, this won't work as Git doesn't know which to use. In that case you can use either:



                git checkout --track origin/test


                or



                git checkout -b test origin/test


                In 2.19, Git learned the checkout.defaultRemote configuration, which specifies a remote to default to when resolving such an ambiguity.






                share|improve this answer




























                  up vote
                  2
                  down vote













                  Please follow the command to create an empty folder. Enter that and use this command:



                  saifurs-Mini:YO-iOS saifurrahman$ git clone your_project_url
                  Cloning into 'iPhoneV1'...
                  remote: Counting objects: 34230, done.
                  remote: Compressing objects: 100% (24028/24028), done.
                  remote: Total 34230 (delta 22212), reused 15340 (delta 9324)
                  Receiving objects: 100% (34230/34230), 202.53 MiB | 294.00 KiB/s, done.
                  Resolving deltas: 100% (22212/22212), done.
                  Checking connectivity... done.
                  saifurs-Mini:YO-iOS saifurrahman$ cd iPhoneV1/
                  saifurs-Mini:iPhoneV1 saifurrahman$ git checkout 1_4_0_content_discovery
                  Branch 1_4_0_content_discovery set up to track remote branch 1_4_0_content_discovery from origin.
                  Switched to a new branch '1_4_0_content_discovery'





                  share|improve this answer






























                    up vote
                    2
                    down vote













                    I was stuck in a situation seeing error: pathspec 'desired-branch' did not match any file(s) known to git. for all of the suggestions above. I'm on git version 1.8.3.1.



                    So this worked for me:



                    git fetch origin desired-branch
                    git checkout -b desired-branch FETCH_HEAD


                    The explanation behind is that I've noticed that when fetching the remote branch, it was fetched to FETCH_HEAD:



                    $ git fetch origin desired-branch
                    From github.com:MYTEAM/my-repo
                    * branch desired-branch -> FETCH_HEAD





                    share|improve this answer




























                      up vote
                      1
                      down vote













                      Fetch origin and checkout the branch.



                      git fetch origin && git checkout branch_name 





                      share|improve this answer






























                        up vote
                        0
                        down vote













                        If the remote branch name begins with special characteres you need to use single quotes around it in the checkout command, or else git won't know which branch you are talking about.



                        For example, I tried to checkout a remote branch named as #9773 but the command didn't work properly, as shown in the picture below:



                        enter image description here



                        For some reason I wondered if the sharp symbol (#) could have something to do with it, and then I tried surrounding the branch name with single quotes, like '#9773' rathen than just #9773, and it worked fine.



                        $ git checkout -b '#9773' origin/'#9773'





                        share|improve this answer





















                        • In many unix shells the # character is used for comments so anything after the # will be ignored. This is a shell thing and not something specific to git. Using quotes of a backslash before the # should be enough.
                          – Paulo Scardine
                          Nov 7 at 12:12










                        protected by Praveen May 9 '13 at 10:07



                        Thank you for your interest in this question.
                        Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                        Would you like to answer one of these unanswered questions instead?














                        26 Answers
                        26






                        active

                        oldest

                        votes








                        26 Answers
                        26






                        active

                        oldest

                        votes









                        active

                        oldest

                        votes






                        active

                        oldest

                        votes








                        up vote
                        7752
                        down vote



                        accepted










                        Update



                        Jakub's answer actually improves on this. With Git versions ≥ 1.6.6, with only one remote, you can just do:



                        git fetch
                        git checkout test


                        As user masukomi points out in a comment, git checkout test will NOT work in modern git if you have multiple remotes. In this case use



                        git checkout -b test <name of remote>/test


                        Old Answer



                        Before you can start working locally on a remote branch, you need to fetch it as called out in answers below.



                        To fetch a branch, you simply need to:



                        git fetch origin


                        This will fetch all of the remote branches for you. You can see the branches available for checkout with:



                        git branch -v -a


                        With the remote branches in hand, you now need to check out the branch you are interested in, giving you a local working copy:



                        git checkout -b test origin/test





                        share|improve this answer



















                        • 354




                          To expand on this: git doesn't allow you to work on someone else's branches. You can only work on your own. So if you want to add to someone else's branch, you need to create your own "copy" of that branch, which is what the above command does (well, it creates your branch and checks it out, too).
                          – Dan Moulding
                          Nov 23 '09 at 15:24






                        • 130




                          If it's a new remote branch you may need to git fetch before doing this so that git is aware of origin/test
                          – Neil Sarkar
                          Nov 4 '11 at 14:38








                        • 53




                          ...and you would do this with git fetch origin test
                          – Andrew
                          Jan 22 '12 at 23:24






                        • 19




                          Error: "git checkout: updating paths is incompatible with switching branches. Did you intend to checkout origin/test which can not be resolved as commit?"
                          – Xeoncross
                          Sep 11 '12 at 20:35








                        • 75




                          git checkout test will NOT work in modern git if you have multiple remotes which have the same branch name. It can't know which one to use.
                          – masukomi
                          Sep 16 '14 at 15:34















                        up vote
                        7752
                        down vote



                        accepted










                        Update



                        Jakub's answer actually improves on this. With Git versions ≥ 1.6.6, with only one remote, you can just do:



                        git fetch
                        git checkout test


                        As user masukomi points out in a comment, git checkout test will NOT work in modern git if you have multiple remotes. In this case use



                        git checkout -b test <name of remote>/test


                        Old Answer



                        Before you can start working locally on a remote branch, you need to fetch it as called out in answers below.



                        To fetch a branch, you simply need to:



                        git fetch origin


                        This will fetch all of the remote branches for you. You can see the branches available for checkout with:



                        git branch -v -a


                        With the remote branches in hand, you now need to check out the branch you are interested in, giving you a local working copy:



                        git checkout -b test origin/test





                        share|improve this answer



















                        • 354




                          To expand on this: git doesn't allow you to work on someone else's branches. You can only work on your own. So if you want to add to someone else's branch, you need to create your own "copy" of that branch, which is what the above command does (well, it creates your branch and checks it out, too).
                          – Dan Moulding
                          Nov 23 '09 at 15:24






                        • 130




                          If it's a new remote branch you may need to git fetch before doing this so that git is aware of origin/test
                          – Neil Sarkar
                          Nov 4 '11 at 14:38








                        • 53




                          ...and you would do this with git fetch origin test
                          – Andrew
                          Jan 22 '12 at 23:24






                        • 19




                          Error: "git checkout: updating paths is incompatible with switching branches. Did you intend to checkout origin/test which can not be resolved as commit?"
                          – Xeoncross
                          Sep 11 '12 at 20:35








                        • 75




                          git checkout test will NOT work in modern git if you have multiple remotes which have the same branch name. It can't know which one to use.
                          – masukomi
                          Sep 16 '14 at 15:34













                        up vote
                        7752
                        down vote



                        accepted







                        up vote
                        7752
                        down vote



                        accepted






                        Update



                        Jakub's answer actually improves on this. With Git versions ≥ 1.6.6, with only one remote, you can just do:



                        git fetch
                        git checkout test


                        As user masukomi points out in a comment, git checkout test will NOT work in modern git if you have multiple remotes. In this case use



                        git checkout -b test <name of remote>/test


                        Old Answer



                        Before you can start working locally on a remote branch, you need to fetch it as called out in answers below.



                        To fetch a branch, you simply need to:



                        git fetch origin


                        This will fetch all of the remote branches for you. You can see the branches available for checkout with:



                        git branch -v -a


                        With the remote branches in hand, you now need to check out the branch you are interested in, giving you a local working copy:



                        git checkout -b test origin/test





                        share|improve this answer














                        Update



                        Jakub's answer actually improves on this. With Git versions ≥ 1.6.6, with only one remote, you can just do:



                        git fetch
                        git checkout test


                        As user masukomi points out in a comment, git checkout test will NOT work in modern git if you have multiple remotes. In this case use



                        git checkout -b test <name of remote>/test


                        Old Answer



                        Before you can start working locally on a remote branch, you need to fetch it as called out in answers below.



                        To fetch a branch, you simply need to:



                        git fetch origin


                        This will fetch all of the remote branches for you. You can see the branches available for checkout with:



                        git branch -v -a


                        With the remote branches in hand, you now need to check out the branch you are interested in, giving you a local working copy:



                        git checkout -b test origin/test






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Oct 13 at 10:16









                        holdenweb

                        14.7k42949




                        14.7k42949










                        answered Nov 23 '09 at 14:26









                        hallski

                        86.1k42721




                        86.1k42721








                        • 354




                          To expand on this: git doesn't allow you to work on someone else's branches. You can only work on your own. So if you want to add to someone else's branch, you need to create your own "copy" of that branch, which is what the above command does (well, it creates your branch and checks it out, too).
                          – Dan Moulding
                          Nov 23 '09 at 15:24






                        • 130




                          If it's a new remote branch you may need to git fetch before doing this so that git is aware of origin/test
                          – Neil Sarkar
                          Nov 4 '11 at 14:38








                        • 53




                          ...and you would do this with git fetch origin test
                          – Andrew
                          Jan 22 '12 at 23:24






                        • 19




                          Error: "git checkout: updating paths is incompatible with switching branches. Did you intend to checkout origin/test which can not be resolved as commit?"
                          – Xeoncross
                          Sep 11 '12 at 20:35








                        • 75




                          git checkout test will NOT work in modern git if you have multiple remotes which have the same branch name. It can't know which one to use.
                          – masukomi
                          Sep 16 '14 at 15:34














                        • 354




                          To expand on this: git doesn't allow you to work on someone else's branches. You can only work on your own. So if you want to add to someone else's branch, you need to create your own "copy" of that branch, which is what the above command does (well, it creates your branch and checks it out, too).
                          – Dan Moulding
                          Nov 23 '09 at 15:24






                        • 130




                          If it's a new remote branch you may need to git fetch before doing this so that git is aware of origin/test
                          – Neil Sarkar
                          Nov 4 '11 at 14:38








                        • 53




                          ...and you would do this with git fetch origin test
                          – Andrew
                          Jan 22 '12 at 23:24






                        • 19




                          Error: "git checkout: updating paths is incompatible with switching branches. Did you intend to checkout origin/test which can not be resolved as commit?"
                          – Xeoncross
                          Sep 11 '12 at 20:35








                        • 75




                          git checkout test will NOT work in modern git if you have multiple remotes which have the same branch name. It can't know which one to use.
                          – masukomi
                          Sep 16 '14 at 15:34








                        354




                        354




                        To expand on this: git doesn't allow you to work on someone else's branches. You can only work on your own. So if you want to add to someone else's branch, you need to create your own "copy" of that branch, which is what the above command does (well, it creates your branch and checks it out, too).
                        – Dan Moulding
                        Nov 23 '09 at 15:24




                        To expand on this: git doesn't allow you to work on someone else's branches. You can only work on your own. So if you want to add to someone else's branch, you need to create your own "copy" of that branch, which is what the above command does (well, it creates your branch and checks it out, too).
                        – Dan Moulding
                        Nov 23 '09 at 15:24




                        130




                        130




                        If it's a new remote branch you may need to git fetch before doing this so that git is aware of origin/test
                        – Neil Sarkar
                        Nov 4 '11 at 14:38






                        If it's a new remote branch you may need to git fetch before doing this so that git is aware of origin/test
                        – Neil Sarkar
                        Nov 4 '11 at 14:38






                        53




                        53




                        ...and you would do this with git fetch origin test
                        – Andrew
                        Jan 22 '12 at 23:24




                        ...and you would do this with git fetch origin test
                        – Andrew
                        Jan 22 '12 at 23:24




                        19




                        19




                        Error: "git checkout: updating paths is incompatible with switching branches. Did you intend to checkout origin/test which can not be resolved as commit?"
                        – Xeoncross
                        Sep 11 '12 at 20:35






                        Error: "git checkout: updating paths is incompatible with switching branches. Did you intend to checkout origin/test which can not be resolved as commit?"
                        – Xeoncross
                        Sep 11 '12 at 20:35






                        75




                        75




                        git checkout test will NOT work in modern git if you have multiple remotes which have the same branch name. It can't know which one to use.
                        – masukomi
                        Sep 16 '14 at 15:34




                        git checkout test will NOT work in modern git if you have multiple remotes which have the same branch name. It can't know which one to use.
                        – masukomi
                        Sep 16 '14 at 15:34












                        up vote
                        1122
                        down vote













                        Sidenote: With modern Git (>= 1.6.6), you are able to use just



                        git checkout test


                        (note that it is 'test' not 'origin/test') to perform magical DWIM-mery and create local branch 'test' for you, for which upstream would be remote-tracking branch 'origin/test'.





                        The * (no branch) in git branch output means that you are on unnamed branch, in so called "detached HEAD" state (HEAD points directly to commit, and is not symbolic reference to some local branch). If you made some commits on this unnamed branch, you can always create local branch off current commit:



                        git checkout -b test HEAD





                        share|improve this answer



















                        • 29




                          Unsurprising, but this version has been released in the last few years - knowing this syntax can save a lot of time since there's still a lot of old documentation and comment threads floating around that suggest the older method for doing this.
                          – Curtis
                          Apr 16 '12 at 13:24






                        • 10




                          "modern git"--for the record, (approx) what version are you referring to? Sometimes we have to work on systems running older distros.
                          – Craig McQueen
                          Aug 28 '12 at 2:30








                        • 5




                          "modern git" in this context is git 1.6.6
                          – Bobby Norton
                          Mar 19 '13 at 20:29








                        • 10




                          @aidan If you get a response like error: pathspec 'branch_name' did not match any file(s) known to git. then you should do a git fetch first.
                          – Dennis
                          Oct 18 '13 at 0:40






                        • 4




                          Using git version 1.8.3.msysgit.0 and this doesn't work for me - did not match any file(s) known to git - I've done many git fetches
                          – PandaWood
                          Dec 3 '13 at 23:59















                        up vote
                        1122
                        down vote













                        Sidenote: With modern Git (>= 1.6.6), you are able to use just



                        git checkout test


                        (note that it is 'test' not 'origin/test') to perform magical DWIM-mery and create local branch 'test' for you, for which upstream would be remote-tracking branch 'origin/test'.





                        The * (no branch) in git branch output means that you are on unnamed branch, in so called "detached HEAD" state (HEAD points directly to commit, and is not symbolic reference to some local branch). If you made some commits on this unnamed branch, you can always create local branch off current commit:



                        git checkout -b test HEAD





                        share|improve this answer



















                        • 29




                          Unsurprising, but this version has been released in the last few years - knowing this syntax can save a lot of time since there's still a lot of old documentation and comment threads floating around that suggest the older method for doing this.
                          – Curtis
                          Apr 16 '12 at 13:24






                        • 10




                          "modern git"--for the record, (approx) what version are you referring to? Sometimes we have to work on systems running older distros.
                          – Craig McQueen
                          Aug 28 '12 at 2:30








                        • 5




                          "modern git" in this context is git 1.6.6
                          – Bobby Norton
                          Mar 19 '13 at 20:29








                        • 10




                          @aidan If you get a response like error: pathspec 'branch_name' did not match any file(s) known to git. then you should do a git fetch first.
                          – Dennis
                          Oct 18 '13 at 0:40






                        • 4




                          Using git version 1.8.3.msysgit.0 and this doesn't work for me - did not match any file(s) known to git - I've done many git fetches
                          – PandaWood
                          Dec 3 '13 at 23:59













                        up vote
                        1122
                        down vote










                        up vote
                        1122
                        down vote









                        Sidenote: With modern Git (>= 1.6.6), you are able to use just



                        git checkout test


                        (note that it is 'test' not 'origin/test') to perform magical DWIM-mery and create local branch 'test' for you, for which upstream would be remote-tracking branch 'origin/test'.





                        The * (no branch) in git branch output means that you are on unnamed branch, in so called "detached HEAD" state (HEAD points directly to commit, and is not symbolic reference to some local branch). If you made some commits on this unnamed branch, you can always create local branch off current commit:



                        git checkout -b test HEAD





                        share|improve this answer














                        Sidenote: With modern Git (>= 1.6.6), you are able to use just



                        git checkout test


                        (note that it is 'test' not 'origin/test') to perform magical DWIM-mery and create local branch 'test' for you, for which upstream would be remote-tracking branch 'origin/test'.





                        The * (no branch) in git branch output means that you are on unnamed branch, in so called "detached HEAD" state (HEAD points directly to commit, and is not symbolic reference to some local branch). If you made some commits on this unnamed branch, you can always create local branch off current commit:



                        git checkout -b test HEAD






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Feb 24 '14 at 19:45









                        Aerovistae

                        16.4k2895160




                        16.4k2895160










                        answered Nov 24 '09 at 0:17









                        Jakub Narębski

                        207k55194222




                        207k55194222








                        • 29




                          Unsurprising, but this version has been released in the last few years - knowing this syntax can save a lot of time since there's still a lot of old documentation and comment threads floating around that suggest the older method for doing this.
                          – Curtis
                          Apr 16 '12 at 13:24






                        • 10




                          "modern git"--for the record, (approx) what version are you referring to? Sometimes we have to work on systems running older distros.
                          – Craig McQueen
                          Aug 28 '12 at 2:30








                        • 5




                          "modern git" in this context is git 1.6.6
                          – Bobby Norton
                          Mar 19 '13 at 20:29








                        • 10




                          @aidan If you get a response like error: pathspec 'branch_name' did not match any file(s) known to git. then you should do a git fetch first.
                          – Dennis
                          Oct 18 '13 at 0:40






                        • 4




                          Using git version 1.8.3.msysgit.0 and this doesn't work for me - did not match any file(s) known to git - I've done many git fetches
                          – PandaWood
                          Dec 3 '13 at 23:59














                        • 29




                          Unsurprising, but this version has been released in the last few years - knowing this syntax can save a lot of time since there's still a lot of old documentation and comment threads floating around that suggest the older method for doing this.
                          – Curtis
                          Apr 16 '12 at 13:24






                        • 10




                          "modern git"--for the record, (approx) what version are you referring to? Sometimes we have to work on systems running older distros.
                          – Craig McQueen
                          Aug 28 '12 at 2:30








                        • 5




                          "modern git" in this context is git 1.6.6
                          – Bobby Norton
                          Mar 19 '13 at 20:29








                        • 10




                          @aidan If you get a response like error: pathspec 'branch_name' did not match any file(s) known to git. then you should do a git fetch first.
                          – Dennis
                          Oct 18 '13 at 0:40






                        • 4




                          Using git version 1.8.3.msysgit.0 and this doesn't work for me - did not match any file(s) known to git - I've done many git fetches
                          – PandaWood
                          Dec 3 '13 at 23:59








                        29




                        29




                        Unsurprising, but this version has been released in the last few years - knowing this syntax can save a lot of time since there's still a lot of old documentation and comment threads floating around that suggest the older method for doing this.
                        – Curtis
                        Apr 16 '12 at 13:24




                        Unsurprising, but this version has been released in the last few years - knowing this syntax can save a lot of time since there's still a lot of old documentation and comment threads floating around that suggest the older method for doing this.
                        – Curtis
                        Apr 16 '12 at 13:24




                        10




                        10




                        "modern git"--for the record, (approx) what version are you referring to? Sometimes we have to work on systems running older distros.
                        – Craig McQueen
                        Aug 28 '12 at 2:30






                        "modern git"--for the record, (approx) what version are you referring to? Sometimes we have to work on systems running older distros.
                        – Craig McQueen
                        Aug 28 '12 at 2:30






                        5




                        5




                        "modern git" in this context is git 1.6.6
                        – Bobby Norton
                        Mar 19 '13 at 20:29






                        "modern git" in this context is git 1.6.6
                        – Bobby Norton
                        Mar 19 '13 at 20:29






                        10




                        10




                        @aidan If you get a response like error: pathspec 'branch_name' did not match any file(s) known to git. then you should do a git fetch first.
                        – Dennis
                        Oct 18 '13 at 0:40




                        @aidan If you get a response like error: pathspec 'branch_name' did not match any file(s) known to git. then you should do a git fetch first.
                        – Dennis
                        Oct 18 '13 at 0:40




                        4




                        4




                        Using git version 1.8.3.msysgit.0 and this doesn't work for me - did not match any file(s) known to git - I've done many git fetches
                        – PandaWood
                        Dec 3 '13 at 23:59




                        Using git version 1.8.3.msysgit.0 and this doesn't work for me - did not match any file(s) known to git - I've done many git fetches
                        – PandaWood
                        Dec 3 '13 at 23:59










                        up vote
                        499
                        down vote













                        In this case, you probably want to create a local test branch which is tracking the remote test branch:



                        $ git branch test origin/test


                        In earlier versions of git, you needed an explicit --track option, but that is the default now when you are branching off a remote branch.






                        share|improve this answer



















                        • 12




                          This will create a local branch without switching to it.
                          – Alex.Designworks
                          Oct 16 '13 at 7:20






                        • 2




                          Though I got fatal: Ambiguous object name: 'origin/dev' - where a branch 'dev' on origin most definitely exists - but I'd accidentally created a branch called "origin/dev" on my machine (in my previous stupid attempts to get this right, no doubt) ... ouch
                          – PandaWood
                          Dec 4 '13 at 0:04








                        • 1




                          This has been giving me the error error: failed to push some refs to hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. Check out this branch and merge the remote changes hint: (e.g. 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
                          – pal4life
                          Jun 18 '14 at 20:01










                        • git branch test works for me
                          – Isaac Pak
                          Feb 17 '17 at 15:27

















                        up vote
                        499
                        down vote













                        In this case, you probably want to create a local test branch which is tracking the remote test branch:



                        $ git branch test origin/test


                        In earlier versions of git, you needed an explicit --track option, but that is the default now when you are branching off a remote branch.






                        share|improve this answer



















                        • 12




                          This will create a local branch without switching to it.
                          – Alex.Designworks
                          Oct 16 '13 at 7:20






                        • 2




                          Though I got fatal: Ambiguous object name: 'origin/dev' - where a branch 'dev' on origin most definitely exists - but I'd accidentally created a branch called "origin/dev" on my machine (in my previous stupid attempts to get this right, no doubt) ... ouch
                          – PandaWood
                          Dec 4 '13 at 0:04








                        • 1




                          This has been giving me the error error: failed to push some refs to hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. Check out this branch and merge the remote changes hint: (e.g. 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
                          – pal4life
                          Jun 18 '14 at 20:01










                        • git branch test works for me
                          – Isaac Pak
                          Feb 17 '17 at 15:27















                        up vote
                        499
                        down vote










                        up vote
                        499
                        down vote









                        In this case, you probably want to create a local test branch which is tracking the remote test branch:



                        $ git branch test origin/test


                        In earlier versions of git, you needed an explicit --track option, but that is the default now when you are branching off a remote branch.






                        share|improve this answer














                        In this case, you probably want to create a local test branch which is tracking the remote test branch:



                        $ git branch test origin/test


                        In earlier versions of git, you needed an explicit --track option, but that is the default now when you are branching off a remote branch.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Feb 24 '16 at 9:06

























                        answered Nov 23 '09 at 14:27









                        ndim

                        24.4k113853




                        24.4k113853








                        • 12




                          This will create a local branch without switching to it.
                          – Alex.Designworks
                          Oct 16 '13 at 7:20






                        • 2




                          Though I got fatal: Ambiguous object name: 'origin/dev' - where a branch 'dev' on origin most definitely exists - but I'd accidentally created a branch called "origin/dev" on my machine (in my previous stupid attempts to get this right, no doubt) ... ouch
                          – PandaWood
                          Dec 4 '13 at 0:04








                        • 1




                          This has been giving me the error error: failed to push some refs to hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. Check out this branch and merge the remote changes hint: (e.g. 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
                          – pal4life
                          Jun 18 '14 at 20:01










                        • git branch test works for me
                          – Isaac Pak
                          Feb 17 '17 at 15:27
















                        • 12




                          This will create a local branch without switching to it.
                          – Alex.Designworks
                          Oct 16 '13 at 7:20






                        • 2




                          Though I got fatal: Ambiguous object name: 'origin/dev' - where a branch 'dev' on origin most definitely exists - but I'd accidentally created a branch called "origin/dev" on my machine (in my previous stupid attempts to get this right, no doubt) ... ouch
                          – PandaWood
                          Dec 4 '13 at 0:04








                        • 1




                          This has been giving me the error error: failed to push some refs to hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. Check out this branch and merge the remote changes hint: (e.g. 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
                          – pal4life
                          Jun 18 '14 at 20:01










                        • git branch test works for me
                          – Isaac Pak
                          Feb 17 '17 at 15:27










                        12




                        12




                        This will create a local branch without switching to it.
                        – Alex.Designworks
                        Oct 16 '13 at 7:20




                        This will create a local branch without switching to it.
                        – Alex.Designworks
                        Oct 16 '13 at 7:20




                        2




                        2




                        Though I got fatal: Ambiguous object name: 'origin/dev' - where a branch 'dev' on origin most definitely exists - but I'd accidentally created a branch called "origin/dev" on my machine (in my previous stupid attempts to get this right, no doubt) ... ouch
                        – PandaWood
                        Dec 4 '13 at 0:04






                        Though I got fatal: Ambiguous object name: 'origin/dev' - where a branch 'dev' on origin most definitely exists - but I'd accidentally created a branch called "origin/dev" on my machine (in my previous stupid attempts to get this right, no doubt) ... ouch
                        – PandaWood
                        Dec 4 '13 at 0:04






                        1




                        1




                        This has been giving me the error error: failed to push some refs to hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. Check out this branch and merge the remote changes hint: (e.g. 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
                        – pal4life
                        Jun 18 '14 at 20:01




                        This has been giving me the error error: failed to push some refs to hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. Check out this branch and merge the remote changes hint: (e.g. 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
                        – pal4life
                        Jun 18 '14 at 20:01












                        git branch test works for me
                        – Isaac Pak
                        Feb 17 '17 at 15:27






                        git branch test works for me
                        – Isaac Pak
                        Feb 17 '17 at 15:27












                        up vote
                        415
                        down vote














                        Accepted answer not working for you?



                        While the first and selected answer is technically correct, there's the possibility you have not yet retrieved all objects and refs from the remote repository. If that is the case, you'll receive the following error:



                        $ git checkout -b remote_branch origin/remote_branch



                        fatal: git checkout: updating paths is incompatible with switching branches.

                        Did you intend to checkout 'origin/remote_branch' which can not be resolved as commit?




                        Solution



                        If you receive this message, you must first do a git fetch origin where origin is the name of the remote repository prior to running git checkout remote_branch. Here's a full example with responses:



                        $ git fetch origin
                        remote: Counting objects: 140, done.
                        remote: Compressing objects: 100% (30/30), done.
                        remote: Total 69 (delta 36), reused 66 (delta 33)
                        Unpacking objects: 100% (69/69), done.
                        From https://github.com/githubuser/repo-name
                        e6ef1e0..5029161 develop -> origin/develop
                        * [new branch] demo -> origin/demo
                        d80f8d7..359eab0 master -> origin/master

                        $ git checkout demo
                        Branch demo set up to track remote branch demo from origin.
                        Switched to a new branch 'demo'


                        As you can see, running git fetch origin retrieved any remote branches we were not yet setup to track on our local machine. From there, since we now have a ref to the remote branch, we can simply run git checkout remote_branch and we'll gain the benefits of remote tracking.






                        share|improve this answer



















                        • 2




                          I'll add a note if you have a separate branch locally: Make sure you have associated this with the remote repo using 'git remote add origin [the_path_to_your_repo/repo_name.git]' . Then use 'git fetch origin' where 'origin' means the origin repository you have made the association with.
                          – elliotrock
                          Feb 2 '15 at 5:51










                        • git checkout -b newbranch also works great for 1-step create and checkout a new branch based on the current branch.
                          – Linus
                          May 19 '16 at 13:41






                        • 2




                          I think this is the most up-to-date (it keeps $@#!ing changing!). Git 2.5.5 I found the only way to actually see the remote branches was git ls-remote and the only way to actually use one is git checkout -b [branch] --track [remote/branch]...and that's after git pull [remote] [branch] worked. I.e., it actually pulled the whole branch, but still wouldn't list it.
                          – delicateLatticeworkFever
                          May 26 '16 at 12:51












                        • and when this answer doesn't work either, see this one.
                          – eis
                          Jan 16 at 12:48















                        up vote
                        415
                        down vote














                        Accepted answer not working for you?



                        While the first and selected answer is technically correct, there's the possibility you have not yet retrieved all objects and refs from the remote repository. If that is the case, you'll receive the following error:



                        $ git checkout -b remote_branch origin/remote_branch



                        fatal: git checkout: updating paths is incompatible with switching branches.

                        Did you intend to checkout 'origin/remote_branch' which can not be resolved as commit?




                        Solution



                        If you receive this message, you must first do a git fetch origin where origin is the name of the remote repository prior to running git checkout remote_branch. Here's a full example with responses:



                        $ git fetch origin
                        remote: Counting objects: 140, done.
                        remote: Compressing objects: 100% (30/30), done.
                        remote: Total 69 (delta 36), reused 66 (delta 33)
                        Unpacking objects: 100% (69/69), done.
                        From https://github.com/githubuser/repo-name
                        e6ef1e0..5029161 develop -> origin/develop
                        * [new branch] demo -> origin/demo
                        d80f8d7..359eab0 master -> origin/master

                        $ git checkout demo
                        Branch demo set up to track remote branch demo from origin.
                        Switched to a new branch 'demo'


                        As you can see, running git fetch origin retrieved any remote branches we were not yet setup to track on our local machine. From there, since we now have a ref to the remote branch, we can simply run git checkout remote_branch and we'll gain the benefits of remote tracking.






                        share|improve this answer



















                        • 2




                          I'll add a note if you have a separate branch locally: Make sure you have associated this with the remote repo using 'git remote add origin [the_path_to_your_repo/repo_name.git]' . Then use 'git fetch origin' where 'origin' means the origin repository you have made the association with.
                          – elliotrock
                          Feb 2 '15 at 5:51










                        • git checkout -b newbranch also works great for 1-step create and checkout a new branch based on the current branch.
                          – Linus
                          May 19 '16 at 13:41






                        • 2




                          I think this is the most up-to-date (it keeps $@#!ing changing!). Git 2.5.5 I found the only way to actually see the remote branches was git ls-remote and the only way to actually use one is git checkout -b [branch] --track [remote/branch]...and that's after git pull [remote] [branch] worked. I.e., it actually pulled the whole branch, but still wouldn't list it.
                          – delicateLatticeworkFever
                          May 26 '16 at 12:51












                        • and when this answer doesn't work either, see this one.
                          – eis
                          Jan 16 at 12:48













                        up vote
                        415
                        down vote










                        up vote
                        415
                        down vote










                        Accepted answer not working for you?



                        While the first and selected answer is technically correct, there's the possibility you have not yet retrieved all objects and refs from the remote repository. If that is the case, you'll receive the following error:



                        $ git checkout -b remote_branch origin/remote_branch



                        fatal: git checkout: updating paths is incompatible with switching branches.

                        Did you intend to checkout 'origin/remote_branch' which can not be resolved as commit?




                        Solution



                        If you receive this message, you must first do a git fetch origin where origin is the name of the remote repository prior to running git checkout remote_branch. Here's a full example with responses:



                        $ git fetch origin
                        remote: Counting objects: 140, done.
                        remote: Compressing objects: 100% (30/30), done.
                        remote: Total 69 (delta 36), reused 66 (delta 33)
                        Unpacking objects: 100% (69/69), done.
                        From https://github.com/githubuser/repo-name
                        e6ef1e0..5029161 develop -> origin/develop
                        * [new branch] demo -> origin/demo
                        d80f8d7..359eab0 master -> origin/master

                        $ git checkout demo
                        Branch demo set up to track remote branch demo from origin.
                        Switched to a new branch 'demo'


                        As you can see, running git fetch origin retrieved any remote branches we were not yet setup to track on our local machine. From there, since we now have a ref to the remote branch, we can simply run git checkout remote_branch and we'll gain the benefits of remote tracking.






                        share|improve this answer















                        Accepted answer not working for you?



                        While the first and selected answer is technically correct, there's the possibility you have not yet retrieved all objects and refs from the remote repository. If that is the case, you'll receive the following error:



                        $ git checkout -b remote_branch origin/remote_branch



                        fatal: git checkout: updating paths is incompatible with switching branches.

                        Did you intend to checkout 'origin/remote_branch' which can not be resolved as commit?




                        Solution



                        If you receive this message, you must first do a git fetch origin where origin is the name of the remote repository prior to running git checkout remote_branch. Here's a full example with responses:



                        $ git fetch origin
                        remote: Counting objects: 140, done.
                        remote: Compressing objects: 100% (30/30), done.
                        remote: Total 69 (delta 36), reused 66 (delta 33)
                        Unpacking objects: 100% (69/69), done.
                        From https://github.com/githubuser/repo-name
                        e6ef1e0..5029161 develop -> origin/develop
                        * [new branch] demo -> origin/demo
                        d80f8d7..359eab0 master -> origin/master

                        $ git checkout demo
                        Branch demo set up to track remote branch demo from origin.
                        Switched to a new branch 'demo'


                        As you can see, running git fetch origin retrieved any remote branches we were not yet setup to track on our local machine. From there, since we now have a ref to the remote branch, we can simply run git checkout remote_branch and we'll gain the benefits of remote tracking.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited May 23 '17 at 12:26









                        Community

                        11




                        11










                        answered Dec 7 '12 at 20:52









                        Corey Ballou

                        29.6k85573




                        29.6k85573








                        • 2




                          I'll add a note if you have a separate branch locally: Make sure you have associated this with the remote repo using 'git remote add origin [the_path_to_your_repo/repo_name.git]' . Then use 'git fetch origin' where 'origin' means the origin repository you have made the association with.
                          – elliotrock
                          Feb 2 '15 at 5:51










                        • git checkout -b newbranch also works great for 1-step create and checkout a new branch based on the current branch.
                          – Linus
                          May 19 '16 at 13:41






                        • 2




                          I think this is the most up-to-date (it keeps $@#!ing changing!). Git 2.5.5 I found the only way to actually see the remote branches was git ls-remote and the only way to actually use one is git checkout -b [branch] --track [remote/branch]...and that's after git pull [remote] [branch] worked. I.e., it actually pulled the whole branch, but still wouldn't list it.
                          – delicateLatticeworkFever
                          May 26 '16 at 12:51












                        • and when this answer doesn't work either, see this one.
                          – eis
                          Jan 16 at 12:48














                        • 2




                          I'll add a note if you have a separate branch locally: Make sure you have associated this with the remote repo using 'git remote add origin [the_path_to_your_repo/repo_name.git]' . Then use 'git fetch origin' where 'origin' means the origin repository you have made the association with.
                          – elliotrock
                          Feb 2 '15 at 5:51










                        • git checkout -b newbranch also works great for 1-step create and checkout a new branch based on the current branch.
                          – Linus
                          May 19 '16 at 13:41






                        • 2




                          I think this is the most up-to-date (it keeps $@#!ing changing!). Git 2.5.5 I found the only way to actually see the remote branches was git ls-remote and the only way to actually use one is git checkout -b [branch] --track [remote/branch]...and that's after git pull [remote] [branch] worked. I.e., it actually pulled the whole branch, but still wouldn't list it.
                          – delicateLatticeworkFever
                          May 26 '16 at 12:51












                        • and when this answer doesn't work either, see this one.
                          – eis
                          Jan 16 at 12:48








                        2




                        2




                        I'll add a note if you have a separate branch locally: Make sure you have associated this with the remote repo using 'git remote add origin [the_path_to_your_repo/repo_name.git]' . Then use 'git fetch origin' where 'origin' means the origin repository you have made the association with.
                        – elliotrock
                        Feb 2 '15 at 5:51




                        I'll add a note if you have a separate branch locally: Make sure you have associated this with the remote repo using 'git remote add origin [the_path_to_your_repo/repo_name.git]' . Then use 'git fetch origin' where 'origin' means the origin repository you have made the association with.
                        – elliotrock
                        Feb 2 '15 at 5:51












                        git checkout -b newbranch also works great for 1-step create and checkout a new branch based on the current branch.
                        – Linus
                        May 19 '16 at 13:41




                        git checkout -b newbranch also works great for 1-step create and checkout a new branch based on the current branch.
                        – Linus
                        May 19 '16 at 13:41




                        2




                        2




                        I think this is the most up-to-date (it keeps $@#!ing changing!). Git 2.5.5 I found the only way to actually see the remote branches was git ls-remote and the only way to actually use one is git checkout -b [branch] --track [remote/branch]...and that's after git pull [remote] [branch] worked. I.e., it actually pulled the whole branch, but still wouldn't list it.
                        – delicateLatticeworkFever
                        May 26 '16 at 12:51






                        I think this is the most up-to-date (it keeps $@#!ing changing!). Git 2.5.5 I found the only way to actually see the remote branches was git ls-remote and the only way to actually use one is git checkout -b [branch] --track [remote/branch]...and that's after git pull [remote] [branch] worked. I.e., it actually pulled the whole branch, but still wouldn't list it.
                        – delicateLatticeworkFever
                        May 26 '16 at 12:51














                        and when this answer doesn't work either, see this one.
                        – eis
                        Jan 16 at 12:48




                        and when this answer doesn't work either, see this one.
                        – eis
                        Jan 16 at 12:48










                        up vote
                        197
                        down vote













                        I tried the above solution, but it didn't work. Try this, it works:



                        git fetch origin 'remote_branch':'local_branch_name'


                        This will fetch the remote branch and create a new local branch (if not exists already) with name local_branch_name and track the remote one in it.






                        share|improve this answer



















                        • 27




                          This worked for me when neither git fetch origin or git remote update created local branches. I'm not sure why.
                          – Godsmith
                          Sep 11 '14 at 8:45






                        • 4




                          This was the most direct way to accomplish what I needed which was to use a remote branch (not master) to create a new branch.
                          – Roralee
                          Nov 13 '15 at 23:15






                        • 7




                          Worked seamlessly, especially when having cloned a single branch from a remote with multiple branches.
                          – Alex C
                          Oct 17 '16 at 10:19






                        • 7




                          this worked for me too, where accepted answers and other high voted didn't. My git version is 2.5.0
                          – pdepmcp
                          Feb 17 '17 at 12:46






                        • 4




                          Does anyone have any idea why this works when everything else doesn't? (I'm on git 2.13.0)
                          – Nathan Arthur
                          Jun 19 '17 at 18:43

















                        up vote
                        197
                        down vote













                        I tried the above solution, but it didn't work. Try this, it works:



                        git fetch origin 'remote_branch':'local_branch_name'


                        This will fetch the remote branch and create a new local branch (if not exists already) with name local_branch_name and track the remote one in it.






                        share|improve this answer



















                        • 27




                          This worked for me when neither git fetch origin or git remote update created local branches. I'm not sure why.
                          – Godsmith
                          Sep 11 '14 at 8:45






                        • 4




                          This was the most direct way to accomplish what I needed which was to use a remote branch (not master) to create a new branch.
                          – Roralee
                          Nov 13 '15 at 23:15






                        • 7




                          Worked seamlessly, especially when having cloned a single branch from a remote with multiple branches.
                          – Alex C
                          Oct 17 '16 at 10:19






                        • 7




                          this worked for me too, where accepted answers and other high voted didn't. My git version is 2.5.0
                          – pdepmcp
                          Feb 17 '17 at 12:46






                        • 4




                          Does anyone have any idea why this works when everything else doesn't? (I'm on git 2.13.0)
                          – Nathan Arthur
                          Jun 19 '17 at 18:43















                        up vote
                        197
                        down vote










                        up vote
                        197
                        down vote









                        I tried the above solution, but it didn't work. Try this, it works:



                        git fetch origin 'remote_branch':'local_branch_name'


                        This will fetch the remote branch and create a new local branch (if not exists already) with name local_branch_name and track the remote one in it.






                        share|improve this answer














                        I tried the above solution, but it didn't work. Try this, it works:



                        git fetch origin 'remote_branch':'local_branch_name'


                        This will fetch the remote branch and create a new local branch (if not exists already) with name local_branch_name and track the remote one in it.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited May 4 '15 at 1:45

























                        answered Oct 18 '13 at 5:55









                        Sahil kalra

                        4,37121825




                        4,37121825








                        • 27




                          This worked for me when neither git fetch origin or git remote update created local branches. I'm not sure why.
                          – Godsmith
                          Sep 11 '14 at 8:45






                        • 4




                          This was the most direct way to accomplish what I needed which was to use a remote branch (not master) to create a new branch.
                          – Roralee
                          Nov 13 '15 at 23:15






                        • 7




                          Worked seamlessly, especially when having cloned a single branch from a remote with multiple branches.
                          – Alex C
                          Oct 17 '16 at 10:19






                        • 7




                          this worked for me too, where accepted answers and other high voted didn't. My git version is 2.5.0
                          – pdepmcp
                          Feb 17 '17 at 12:46






                        • 4




                          Does anyone have any idea why this works when everything else doesn't? (I'm on git 2.13.0)
                          – Nathan Arthur
                          Jun 19 '17 at 18:43
















                        • 27




                          This worked for me when neither git fetch origin or git remote update created local branches. I'm not sure why.
                          – Godsmith
                          Sep 11 '14 at 8:45






                        • 4




                          This was the most direct way to accomplish what I needed which was to use a remote branch (not master) to create a new branch.
                          – Roralee
                          Nov 13 '15 at 23:15






                        • 7




                          Worked seamlessly, especially when having cloned a single branch from a remote with multiple branches.
                          – Alex C
                          Oct 17 '16 at 10:19






                        • 7




                          this worked for me too, where accepted answers and other high voted didn't. My git version is 2.5.0
                          – pdepmcp
                          Feb 17 '17 at 12:46






                        • 4




                          Does anyone have any idea why this works when everything else doesn't? (I'm on git 2.13.0)
                          – Nathan Arthur
                          Jun 19 '17 at 18:43










                        27




                        27




                        This worked for me when neither git fetch origin or git remote update created local branches. I'm not sure why.
                        – Godsmith
                        Sep 11 '14 at 8:45




                        This worked for me when neither git fetch origin or git remote update created local branches. I'm not sure why.
                        – Godsmith
                        Sep 11 '14 at 8:45




                        4




                        4




                        This was the most direct way to accomplish what I needed which was to use a remote branch (not master) to create a new branch.
                        – Roralee
                        Nov 13 '15 at 23:15




                        This was the most direct way to accomplish what I needed which was to use a remote branch (not master) to create a new branch.
                        – Roralee
                        Nov 13 '15 at 23:15




                        7




                        7




                        Worked seamlessly, especially when having cloned a single branch from a remote with multiple branches.
                        – Alex C
                        Oct 17 '16 at 10:19




                        Worked seamlessly, especially when having cloned a single branch from a remote with multiple branches.
                        – Alex C
                        Oct 17 '16 at 10:19




                        7




                        7




                        this worked for me too, where accepted answers and other high voted didn't. My git version is 2.5.0
                        – pdepmcp
                        Feb 17 '17 at 12:46




                        this worked for me too, where accepted answers and other high voted didn't. My git version is 2.5.0
                        – pdepmcp
                        Feb 17 '17 at 12:46




                        4




                        4




                        Does anyone have any idea why this works when everything else doesn't? (I'm on git 2.13.0)
                        – Nathan Arthur
                        Jun 19 '17 at 18:43






                        Does anyone have any idea why this works when everything else doesn't? (I'm on git 2.13.0)
                        – Nathan Arthur
                        Jun 19 '17 at 18:43












                        up vote
                        103
                        down vote













                        This will DWIM for a remote not named origin (documentation):



                        $ git checkout -t remote_name/remote_branch


                        To add a new remote, you will need to do the following first:



                        $ git remote add remote_name location_of_remote
                        $ git fetch remote_name


                        The first tells Git the remote exists, the second gets the commits.






                        share|improve this answer



























                          up vote
                          103
                          down vote













                          This will DWIM for a remote not named origin (documentation):



                          $ git checkout -t remote_name/remote_branch


                          To add a new remote, you will need to do the following first:



                          $ git remote add remote_name location_of_remote
                          $ git fetch remote_name


                          The first tells Git the remote exists, the second gets the commits.






                          share|improve this answer

























                            up vote
                            103
                            down vote










                            up vote
                            103
                            down vote









                            This will DWIM for a remote not named origin (documentation):



                            $ git checkout -t remote_name/remote_branch


                            To add a new remote, you will need to do the following first:



                            $ git remote add remote_name location_of_remote
                            $ git fetch remote_name


                            The first tells Git the remote exists, the second gets the commits.






                            share|improve this answer














                            This will DWIM for a remote not named origin (documentation):



                            $ git checkout -t remote_name/remote_branch


                            To add a new remote, you will need to do the following first:



                            $ git remote add remote_name location_of_remote
                            $ git fetch remote_name


                            The first tells Git the remote exists, the second gets the commits.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jul 13 '14 at 23:09









                            Peter Mortensen

                            13.3k1983111




                            13.3k1983111










                            answered Apr 27 '12 at 22:37









                            tacaswell

                            53.5k9136146




                            53.5k9136146






















                                up vote
                                94
                                down vote













                                Use:



                                git checkout -b <BRANCH-NAME> <REMOTE-NAME>/<BRANCH-NAME>


                                Other answers do not work with modern Git in my benign case. You might need to pull first if the remote branch is new, but I haven't checked that case.






                                share|improve this answer



















                                • 2




                                  Do you realize that this is an extract of this answer
                                  – Thomas Ayoub
                                  Feb 21 '16 at 11:03






                                • 12




                                  Looking at it now, they do overlap. Only mine is succinct and tells you what to do rather than tell a story. I assume it can be more useful therefore, especially for nowadays git versions. You can downvote it if you think it is a bad answer.
                                  – matanster
                                  Feb 21 '16 at 11:34

















                                up vote
                                94
                                down vote













                                Use:



                                git checkout -b <BRANCH-NAME> <REMOTE-NAME>/<BRANCH-NAME>


                                Other answers do not work with modern Git in my benign case. You might need to pull first if the remote branch is new, but I haven't checked that case.






                                share|improve this answer



















                                • 2




                                  Do you realize that this is an extract of this answer
                                  – Thomas Ayoub
                                  Feb 21 '16 at 11:03






                                • 12




                                  Looking at it now, they do overlap. Only mine is succinct and tells you what to do rather than tell a story. I assume it can be more useful therefore, especially for nowadays git versions. You can downvote it if you think it is a bad answer.
                                  – matanster
                                  Feb 21 '16 at 11:34















                                up vote
                                94
                                down vote










                                up vote
                                94
                                down vote









                                Use:



                                git checkout -b <BRANCH-NAME> <REMOTE-NAME>/<BRANCH-NAME>


                                Other answers do not work with modern Git in my benign case. You might need to pull first if the remote branch is new, but I haven't checked that case.






                                share|improve this answer














                                Use:



                                git checkout -b <BRANCH-NAME> <REMOTE-NAME>/<BRANCH-NAME>


                                Other answers do not work with modern Git in my benign case. You might need to pull first if the remote branch is new, but I haven't checked that case.







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Jun 30 '16 at 16:09









                                Peter Mortensen

                                13.3k1983111




                                13.3k1983111










                                answered Feb 21 '16 at 10:58









                                matanster

                                6,319104790




                                6,319104790








                                • 2




                                  Do you realize that this is an extract of this answer
                                  – Thomas Ayoub
                                  Feb 21 '16 at 11:03






                                • 12




                                  Looking at it now, they do overlap. Only mine is succinct and tells you what to do rather than tell a story. I assume it can be more useful therefore, especially for nowadays git versions. You can downvote it if you think it is a bad answer.
                                  – matanster
                                  Feb 21 '16 at 11:34
















                                • 2




                                  Do you realize that this is an extract of this answer
                                  – Thomas Ayoub
                                  Feb 21 '16 at 11:03






                                • 12




                                  Looking at it now, they do overlap. Only mine is succinct and tells you what to do rather than tell a story. I assume it can be more useful therefore, especially for nowadays git versions. You can downvote it if you think it is a bad answer.
                                  – matanster
                                  Feb 21 '16 at 11:34










                                2




                                2




                                Do you realize that this is an extract of this answer
                                – Thomas Ayoub
                                Feb 21 '16 at 11:03




                                Do you realize that this is an extract of this answer
                                – Thomas Ayoub
                                Feb 21 '16 at 11:03




                                12




                                12




                                Looking at it now, they do overlap. Only mine is succinct and tells you what to do rather than tell a story. I assume it can be more useful therefore, especially for nowadays git versions. You can downvote it if you think it is a bad answer.
                                – matanster
                                Feb 21 '16 at 11:34






                                Looking at it now, they do overlap. Only mine is succinct and tells you what to do rather than tell a story. I assume it can be more useful therefore, especially for nowadays git versions. You can downvote it if you think it is a bad answer.
                                – matanster
                                Feb 21 '16 at 11:34












                                up vote
                                60
                                down vote













                                OK, the answer is easy... You basically see the branch, but you don't have a local copy yet!...



                                You need to fetch the branch...



                                You can simply fetch and then checkout to the branch, use the one line command below to do that:



                                git fetch && git checkout test


                                I also created the image below for you to share the differences, look at how fetch works and also how it's different to pull:



                                git fetch






                                share|improve this answer



















                                • 5




                                  Great picture, thanks
                                  – developer
                                  Sep 8 '17 at 10:05










                                • Does not work if there is no local branch test
                                  – Dmitri Zaitsev
                                  Apr 25 at 3:26










                                • @DmitriZaitsev yes, it will work, if the remote branch is there, and you do fetch, you will get the branch locally... git fetch && git checkout test..So this works, unless there is no remote branch, but the question saying there is already a remote branch there...
                                  – Alireza
                                  Apr 25 at 5:13










                                • The way I see the question, test looks like a new branch, so it is not likely to be present locally. Otherwise you could pull it easier with single git pull command.
                                  – Dmitri Zaitsev
                                  Apr 25 at 12:51










                                • @DmitriZaitsev, yes, that's why I said git fetch, that check for remote branches which just created, pull can bring other unwanted stuffs in, but fetch makes all branches available if you already have the repo locally...
                                  – Alireza
                                  Apr 25 at 13:36















                                up vote
                                60
                                down vote













                                OK, the answer is easy... You basically see the branch, but you don't have a local copy yet!...



                                You need to fetch the branch...



                                You can simply fetch and then checkout to the branch, use the one line command below to do that:



                                git fetch && git checkout test


                                I also created the image below for you to share the differences, look at how fetch works and also how it's different to pull:



                                git fetch






                                share|improve this answer



















                                • 5




                                  Great picture, thanks
                                  – developer
                                  Sep 8 '17 at 10:05










                                • Does not work if there is no local branch test
                                  – Dmitri Zaitsev
                                  Apr 25 at 3:26










                                • @DmitriZaitsev yes, it will work, if the remote branch is there, and you do fetch, you will get the branch locally... git fetch && git checkout test..So this works, unless there is no remote branch, but the question saying there is already a remote branch there...
                                  – Alireza
                                  Apr 25 at 5:13










                                • The way I see the question, test looks like a new branch, so it is not likely to be present locally. Otherwise you could pull it easier with single git pull command.
                                  – Dmitri Zaitsev
                                  Apr 25 at 12:51










                                • @DmitriZaitsev, yes, that's why I said git fetch, that check for remote branches which just created, pull can bring other unwanted stuffs in, but fetch makes all branches available if you already have the repo locally...
                                  – Alireza
                                  Apr 25 at 13:36













                                up vote
                                60
                                down vote










                                up vote
                                60
                                down vote









                                OK, the answer is easy... You basically see the branch, but you don't have a local copy yet!...



                                You need to fetch the branch...



                                You can simply fetch and then checkout to the branch, use the one line command below to do that:



                                git fetch && git checkout test


                                I also created the image below for you to share the differences, look at how fetch works and also how it's different to pull:



                                git fetch






                                share|improve this answer














                                OK, the answer is easy... You basically see the branch, but you don't have a local copy yet!...



                                You need to fetch the branch...



                                You can simply fetch and then checkout to the branch, use the one line command below to do that:



                                git fetch && git checkout test


                                I also created the image below for you to share the differences, look at how fetch works and also how it's different to pull:



                                git fetch







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Aug 23 at 13:30

























                                answered Sep 5 '17 at 14:20









                                Alireza

                                42.8k12158118




                                42.8k12158118








                                • 5




                                  Great picture, thanks
                                  – developer
                                  Sep 8 '17 at 10:05










                                • Does not work if there is no local branch test
                                  – Dmitri Zaitsev
                                  Apr 25 at 3:26










                                • @DmitriZaitsev yes, it will work, if the remote branch is there, and you do fetch, you will get the branch locally... git fetch && git checkout test..So this works, unless there is no remote branch, but the question saying there is already a remote branch there...
                                  – Alireza
                                  Apr 25 at 5:13










                                • The way I see the question, test looks like a new branch, so it is not likely to be present locally. Otherwise you could pull it easier with single git pull command.
                                  – Dmitri Zaitsev
                                  Apr 25 at 12:51










                                • @DmitriZaitsev, yes, that's why I said git fetch, that check for remote branches which just created, pull can bring other unwanted stuffs in, but fetch makes all branches available if you already have the repo locally...
                                  – Alireza
                                  Apr 25 at 13:36














                                • 5




                                  Great picture, thanks
                                  – developer
                                  Sep 8 '17 at 10:05










                                • Does not work if there is no local branch test
                                  – Dmitri Zaitsev
                                  Apr 25 at 3:26










                                • @DmitriZaitsev yes, it will work, if the remote branch is there, and you do fetch, you will get the branch locally... git fetch && git checkout test..So this works, unless there is no remote branch, but the question saying there is already a remote branch there...
                                  – Alireza
                                  Apr 25 at 5:13










                                • The way I see the question, test looks like a new branch, so it is not likely to be present locally. Otherwise you could pull it easier with single git pull command.
                                  – Dmitri Zaitsev
                                  Apr 25 at 12:51










                                • @DmitriZaitsev, yes, that's why I said git fetch, that check for remote branches which just created, pull can bring other unwanted stuffs in, but fetch makes all branches available if you already have the repo locally...
                                  – Alireza
                                  Apr 25 at 13:36








                                5




                                5




                                Great picture, thanks
                                – developer
                                Sep 8 '17 at 10:05




                                Great picture, thanks
                                – developer
                                Sep 8 '17 at 10:05












                                Does not work if there is no local branch test
                                – Dmitri Zaitsev
                                Apr 25 at 3:26




                                Does not work if there is no local branch test
                                – Dmitri Zaitsev
                                Apr 25 at 3:26












                                @DmitriZaitsev yes, it will work, if the remote branch is there, and you do fetch, you will get the branch locally... git fetch && git checkout test..So this works, unless there is no remote branch, but the question saying there is already a remote branch there...
                                – Alireza
                                Apr 25 at 5:13




                                @DmitriZaitsev yes, it will work, if the remote branch is there, and you do fetch, you will get the branch locally... git fetch && git checkout test..So this works, unless there is no remote branch, but the question saying there is already a remote branch there...
                                – Alireza
                                Apr 25 at 5:13












                                The way I see the question, test looks like a new branch, so it is not likely to be present locally. Otherwise you could pull it easier with single git pull command.
                                – Dmitri Zaitsev
                                Apr 25 at 12:51




                                The way I see the question, test looks like a new branch, so it is not likely to be present locally. Otherwise you could pull it easier with single git pull command.
                                – Dmitri Zaitsev
                                Apr 25 at 12:51












                                @DmitriZaitsev, yes, that's why I said git fetch, that check for remote branches which just created, pull can bring other unwanted stuffs in, but fetch makes all branches available if you already have the repo locally...
                                – Alireza
                                Apr 25 at 13:36




                                @DmitriZaitsev, yes, that's why I said git fetch, that check for remote branches which just created, pull can bring other unwanted stuffs in, but fetch makes all branches available if you already have the repo locally...
                                – Alireza
                                Apr 25 at 13:36










                                up vote
                                47
                                down vote













                                To clone a Git repository, do:



                                git clone <either ssh url /http url>


                                The above command checks out all of the branches, but only the master branch will be initialized. If you want to checkout the other branches, do:



                                git checkout -t origin/future_branch (for example)


                                This command checks out the remote branch, and your local branch name will be same as the remote branch.



                                If you want to override your local branch name on checkout:



                                git checkout -t -b enhancement origin/future_branch


                                Now your local branch name is enhancement, but your remote branch name is future_branch.



                                Documentation






                                share|improve this answer























                                • git clone <either ssh url /http url> - works perfectly for me
                                  – Kmeixner
                                  Dec 16 '14 at 16:56










                                • Yes you are correct. Thanks for your information, I will update it very soon @warvariuc
                                  – Madhan Ayyasamy
                                  Jan 8 '15 at 10:45










                                • If the remote has no master, this is not going to work.
                                  – polkovnikov.ph
                                  Sep 27 '16 at 16:47















                                up vote
                                47
                                down vote













                                To clone a Git repository, do:



                                git clone <either ssh url /http url>


                                The above command checks out all of the branches, but only the master branch will be initialized. If you want to checkout the other branches, do:



                                git checkout -t origin/future_branch (for example)


                                This command checks out the remote branch, and your local branch name will be same as the remote branch.



                                If you want to override your local branch name on checkout:



                                git checkout -t -b enhancement origin/future_branch


                                Now your local branch name is enhancement, but your remote branch name is future_branch.



                                Documentation






                                share|improve this answer























                                • git clone <either ssh url /http url> - works perfectly for me
                                  – Kmeixner
                                  Dec 16 '14 at 16:56










                                • Yes you are correct. Thanks for your information, I will update it very soon @warvariuc
                                  – Madhan Ayyasamy
                                  Jan 8 '15 at 10:45










                                • If the remote has no master, this is not going to work.
                                  – polkovnikov.ph
                                  Sep 27 '16 at 16:47













                                up vote
                                47
                                down vote










                                up vote
                                47
                                down vote









                                To clone a Git repository, do:



                                git clone <either ssh url /http url>


                                The above command checks out all of the branches, but only the master branch will be initialized. If you want to checkout the other branches, do:



                                git checkout -t origin/future_branch (for example)


                                This command checks out the remote branch, and your local branch name will be same as the remote branch.



                                If you want to override your local branch name on checkout:



                                git checkout -t -b enhancement origin/future_branch


                                Now your local branch name is enhancement, but your remote branch name is future_branch.



                                Documentation






                                share|improve this answer














                                To clone a Git repository, do:



                                git clone <either ssh url /http url>


                                The above command checks out all of the branches, but only the master branch will be initialized. If you want to checkout the other branches, do:



                                git checkout -t origin/future_branch (for example)


                                This command checks out the remote branch, and your local branch name will be same as the remote branch.



                                If you want to override your local branch name on checkout:



                                git checkout -t -b enhancement origin/future_branch


                                Now your local branch name is enhancement, but your remote branch name is future_branch.



                                Documentation







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Jul 13 '14 at 23:11









                                Peter Mortensen

                                13.3k1983111




                                13.3k1983111










                                answered Jan 21 '13 at 10:04









                                Madhan Ayyasamy

                                10k31318




                                10k31318












                                • git clone <either ssh url /http url> - works perfectly for me
                                  – Kmeixner
                                  Dec 16 '14 at 16:56










                                • Yes you are correct. Thanks for your information, I will update it very soon @warvariuc
                                  – Madhan Ayyasamy
                                  Jan 8 '15 at 10:45










                                • If the remote has no master, this is not going to work.
                                  – polkovnikov.ph
                                  Sep 27 '16 at 16:47


















                                • git clone <either ssh url /http url> - works perfectly for me
                                  – Kmeixner
                                  Dec 16 '14 at 16:56










                                • Yes you are correct. Thanks for your information, I will update it very soon @warvariuc
                                  – Madhan Ayyasamy
                                  Jan 8 '15 at 10:45










                                • If the remote has no master, this is not going to work.
                                  – polkovnikov.ph
                                  Sep 27 '16 at 16:47
















                                git clone <either ssh url /http url> - works perfectly for me
                                – Kmeixner
                                Dec 16 '14 at 16:56




                                git clone <either ssh url /http url> - works perfectly for me
                                – Kmeixner
                                Dec 16 '14 at 16:56












                                Yes you are correct. Thanks for your information, I will update it very soon @warvariuc
                                – Madhan Ayyasamy
                                Jan 8 '15 at 10:45




                                Yes you are correct. Thanks for your information, I will update it very soon @warvariuc
                                – Madhan Ayyasamy
                                Jan 8 '15 at 10:45












                                If the remote has no master, this is not going to work.
                                – polkovnikov.ph
                                Sep 27 '16 at 16:47




                                If the remote has no master, this is not going to work.
                                – polkovnikov.ph
                                Sep 27 '16 at 16:47










                                up vote
                                30
                                down vote













                                You can try



                                git fetch remote
                                git checkout --track -b local_branch_name origin/branch_name


                                or



                                git fetch
                                git checkout -b local_branch_name origin/branch_name





                                share|improve this answer



















                                • 2




                                  FYI, --track is no longer needed in newer versions of git, because it's set by default, as explained in this earlier answer.
                                  – user456814
                                  Jun 21 '14 at 18:03















                                up vote
                                30
                                down vote













                                You can try



                                git fetch remote
                                git checkout --track -b local_branch_name origin/branch_name


                                or



                                git fetch
                                git checkout -b local_branch_name origin/branch_name





                                share|improve this answer



















                                • 2




                                  FYI, --track is no longer needed in newer versions of git, because it's set by default, as explained in this earlier answer.
                                  – user456814
                                  Jun 21 '14 at 18:03













                                up vote
                                30
                                down vote










                                up vote
                                30
                                down vote









                                You can try



                                git fetch remote
                                git checkout --track -b local_branch_name origin/branch_name


                                or



                                git fetch
                                git checkout -b local_branch_name origin/branch_name





                                share|improve this answer














                                You can try



                                git fetch remote
                                git checkout --track -b local_branch_name origin/branch_name


                                or



                                git fetch
                                git checkout -b local_branch_name origin/branch_name






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Jul 13 '14 at 23:13









                                Peter Mortensen

                                13.3k1983111




                                13.3k1983111










                                answered Mar 24 '14 at 13:11









                                uma

                                2,1341517




                                2,1341517








                                • 2




                                  FYI, --track is no longer needed in newer versions of git, because it's set by default, as explained in this earlier answer.
                                  – user456814
                                  Jun 21 '14 at 18:03














                                • 2




                                  FYI, --track is no longer needed in newer versions of git, because it's set by default, as explained in this earlier answer.
                                  – user456814
                                  Jun 21 '14 at 18:03








                                2




                                2




                                FYI, --track is no longer needed in newer versions of git, because it's set by default, as explained in this earlier answer.
                                – user456814
                                Jun 21 '14 at 18:03




                                FYI, --track is no longer needed in newer versions of git, because it's set by default, as explained in this earlier answer.
                                – user456814
                                Jun 21 '14 at 18:03










                                up vote
                                27
                                down vote













                                First, you need to do:



                                git fetch # If you don't know about branch name



                                git fetch origin branch_name


                                Second, you can check out remote branch into your local by:



                                git checkout -b branch_name origin/branch_name


                                -b will create new branch in specified name from your selected remote branch.






                                share|improve this answer























                                • I dont understand -b. If you can do "git checkout master" why cant you do "git checkout origin/test"?
                                  – John Little
                                  Jan 23 at 18:16










                                • -b for new branch which is from origin/master
                                  – Mohideen ibn Mohammed
                                  Jan 24 at 1:13















                                up vote
                                27
                                down vote













                                First, you need to do:



                                git fetch # If you don't know about branch name



                                git fetch origin branch_name


                                Second, you can check out remote branch into your local by:



                                git checkout -b branch_name origin/branch_name


                                -b will create new branch in specified name from your selected remote branch.






                                share|improve this answer























                                • I dont understand -b. If you can do "git checkout master" why cant you do "git checkout origin/test"?
                                  – John Little
                                  Jan 23 at 18:16










                                • -b for new branch which is from origin/master
                                  – Mohideen ibn Mohammed
                                  Jan 24 at 1:13













                                up vote
                                27
                                down vote










                                up vote
                                27
                                down vote









                                First, you need to do:



                                git fetch # If you don't know about branch name



                                git fetch origin branch_name


                                Second, you can check out remote branch into your local by:



                                git checkout -b branch_name origin/branch_name


                                -b will create new branch in specified name from your selected remote branch.






                                share|improve this answer














                                First, you need to do:



                                git fetch # If you don't know about branch name



                                git fetch origin branch_name


                                Second, you can check out remote branch into your local by:



                                git checkout -b branch_name origin/branch_name


                                -b will create new branch in specified name from your selected remote branch.







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited May 21 '17 at 11:18









                                Peter Mortensen

                                13.3k1983111




                                13.3k1983111










                                answered May 18 '17 at 13:55









                                Mohideen ibn Mohammed

                                6,81134757




                                6,81134757












                                • I dont understand -b. If you can do "git checkout master" why cant you do "git checkout origin/test"?
                                  – John Little
                                  Jan 23 at 18:16










                                • -b for new branch which is from origin/master
                                  – Mohideen ibn Mohammed
                                  Jan 24 at 1:13


















                                • I dont understand -b. If you can do "git checkout master" why cant you do "git checkout origin/test"?
                                  – John Little
                                  Jan 23 at 18:16










                                • -b for new branch which is from origin/master
                                  – Mohideen ibn Mohammed
                                  Jan 24 at 1:13
















                                I dont understand -b. If you can do "git checkout master" why cant you do "git checkout origin/test"?
                                – John Little
                                Jan 23 at 18:16




                                I dont understand -b. If you can do "git checkout master" why cant you do "git checkout origin/test"?
                                – John Little
                                Jan 23 at 18:16












                                -b for new branch which is from origin/master
                                – Mohideen ibn Mohammed
                                Jan 24 at 1:13




                                -b for new branch which is from origin/master
                                – Mohideen ibn Mohammed
                                Jan 24 at 1:13










                                up vote
                                24
                                down vote













                                Commands



                                git fetch --all
                                git checkout -b <ur_new_local_branch_name> origin/<Remote_Branch_Name>


                                are equal to



                                 git fetch --all


                                and then



                                 git checkout -b fixes_for_dev origin/development


                                Both will create a latest fixes_for_dev from development






                                share|improve this answer



























                                  up vote
                                  24
                                  down vote













                                  Commands



                                  git fetch --all
                                  git checkout -b <ur_new_local_branch_name> origin/<Remote_Branch_Name>


                                  are equal to



                                   git fetch --all


                                  and then



                                   git checkout -b fixes_for_dev origin/development


                                  Both will create a latest fixes_for_dev from development






                                  share|improve this answer

























                                    up vote
                                    24
                                    down vote










                                    up vote
                                    24
                                    down vote









                                    Commands



                                    git fetch --all
                                    git checkout -b <ur_new_local_branch_name> origin/<Remote_Branch_Name>


                                    are equal to



                                     git fetch --all


                                    and then



                                     git checkout -b fixes_for_dev origin/development


                                    Both will create a latest fixes_for_dev from development






                                    share|improve this answer














                                    Commands



                                    git fetch --all
                                    git checkout -b <ur_new_local_branch_name> origin/<Remote_Branch_Name>


                                    are equal to



                                     git fetch --all


                                    and then



                                     git checkout -b fixes_for_dev origin/development


                                    Both will create a latest fixes_for_dev from development







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Apr 21 '16 at 21:58









                                    madhead

                                    13k1381113




                                    13k1381113










                                    answered Apr 21 '16 at 19:10









                                    sreekumar

                                    1,2461421




                                    1,2461421






















                                        up vote
                                        23
                                        down vote













                                        I use the following command:



                                        git checkout --track origin/other_remote_branch





                                        share|improve this answer



















                                        • 8




                                          This answer would be a lot more useful if you explain why you are using it this way. i.e. why someone should use '--track' and so on...
                                          – Matt Friedman
                                          Nov 20 '17 at 3:19















                                        up vote
                                        23
                                        down vote













                                        I use the following command:



                                        git checkout --track origin/other_remote_branch





                                        share|improve this answer



















                                        • 8




                                          This answer would be a lot more useful if you explain why you are using it this way. i.e. why someone should use '--track' and so on...
                                          – Matt Friedman
                                          Nov 20 '17 at 3:19













                                        up vote
                                        23
                                        down vote










                                        up vote
                                        23
                                        down vote









                                        I use the following command:



                                        git checkout --track origin/other_remote_branch





                                        share|improve this answer














                                        I use the following command:



                                        git checkout --track origin/other_remote_branch






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Mar 21 at 18:36









                                        Peter Mortensen

                                        13.3k1983111




                                        13.3k1983111










                                        answered Sep 6 '17 at 14:41









                                        priyankvex

                                        2,90121633




                                        2,90121633








                                        • 8




                                          This answer would be a lot more useful if you explain why you are using it this way. i.e. why someone should use '--track' and so on...
                                          – Matt Friedman
                                          Nov 20 '17 at 3:19














                                        • 8




                                          This answer would be a lot more useful if you explain why you are using it this way. i.e. why someone should use '--track' and so on...
                                          – Matt Friedman
                                          Nov 20 '17 at 3:19








                                        8




                                        8




                                        This answer would be a lot more useful if you explain why you are using it this way. i.e. why someone should use '--track' and so on...
                                        – Matt Friedman
                                        Nov 20 '17 at 3:19




                                        This answer would be a lot more useful if you explain why you are using it this way. i.e. why someone should use '--track' and so on...
                                        – Matt Friedman
                                        Nov 20 '17 at 3:19










                                        up vote
                                        22
                                        down vote













                                        If the branch is on something other than the origin remote I like to do the following:



                                        $ git fetch
                                        $ git checkout -b second/next upstream/next


                                        This will checkout the next branch on the upstream remote in to a local branch called second/next. Which means if you already have a local branch named next it will not conflict.



                                        $ git branch -a
                                        * second/next
                                        remotes/origin/next
                                        remotes/upstream/next





                                        share|improve this answer



























                                          up vote
                                          22
                                          down vote













                                          If the branch is on something other than the origin remote I like to do the following:



                                          $ git fetch
                                          $ git checkout -b second/next upstream/next


                                          This will checkout the next branch on the upstream remote in to a local branch called second/next. Which means if you already have a local branch named next it will not conflict.



                                          $ git branch -a
                                          * second/next
                                          remotes/origin/next
                                          remotes/upstream/next





                                          share|improve this answer

























                                            up vote
                                            22
                                            down vote










                                            up vote
                                            22
                                            down vote









                                            If the branch is on something other than the origin remote I like to do the following:



                                            $ git fetch
                                            $ git checkout -b second/next upstream/next


                                            This will checkout the next branch on the upstream remote in to a local branch called second/next. Which means if you already have a local branch named next it will not conflict.



                                            $ git branch -a
                                            * second/next
                                            remotes/origin/next
                                            remotes/upstream/next





                                            share|improve this answer














                                            If the branch is on something other than the origin remote I like to do the following:



                                            $ git fetch
                                            $ git checkout -b second/next upstream/next


                                            This will checkout the next branch on the upstream remote in to a local branch called second/next. Which means if you already have a local branch named next it will not conflict.



                                            $ git branch -a
                                            * second/next
                                            remotes/origin/next
                                            remotes/upstream/next






                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited May 30 '13 at 5:54









                                            prusswan

                                            5,37732748




                                            5,37732748










                                            answered Mar 1 '13 at 10:00









                                            Kris

                                            10.6k56282




                                            10.6k56282






















                                                up vote
                                                15
                                                down vote













                                                git fetch && git checkout your-branch-name






                                                share|improve this answer

























                                                  up vote
                                                  15
                                                  down vote













                                                  git fetch && git checkout your-branch-name






                                                  share|improve this answer























                                                    up vote
                                                    15
                                                    down vote










                                                    up vote
                                                    15
                                                    down vote









                                                    git fetch && git checkout your-branch-name






                                                    share|improve this answer












                                                    git fetch && git checkout your-branch-name







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Mar 26 '14 at 7:00









                                                    Inder Kumar Rathore

                                                    31.5k1498151




                                                    31.5k1498151






















                                                        up vote
                                                        14
                                                        down vote













                                                        git branch -r says the object name is invalid, because that branch name isn't in Git's local branch list. Update your local branch list from origin with:



                                                        git remote update


                                                        And then try checking out your remote branch again.



                                                        This worked for me.



                                                        I believe git fetch pulls in all remote branches, which is not what the original poster wanted.






                                                        share|improve this answer



















                                                        • 2




                                                          FYI, git remote update will also fetch all remote branches.
                                                          – user456814
                                                          Jun 21 '14 at 17:59

















                                                        up vote
                                                        14
                                                        down vote













                                                        git branch -r says the object name is invalid, because that branch name isn't in Git's local branch list. Update your local branch list from origin with:



                                                        git remote update


                                                        And then try checking out your remote branch again.



                                                        This worked for me.



                                                        I believe git fetch pulls in all remote branches, which is not what the original poster wanted.






                                                        share|improve this answer



















                                                        • 2




                                                          FYI, git remote update will also fetch all remote branches.
                                                          – user456814
                                                          Jun 21 '14 at 17:59















                                                        up vote
                                                        14
                                                        down vote










                                                        up vote
                                                        14
                                                        down vote









                                                        git branch -r says the object name is invalid, because that branch name isn't in Git's local branch list. Update your local branch list from origin with:



                                                        git remote update


                                                        And then try checking out your remote branch again.



                                                        This worked for me.



                                                        I believe git fetch pulls in all remote branches, which is not what the original poster wanted.






                                                        share|improve this answer














                                                        git branch -r says the object name is invalid, because that branch name isn't in Git's local branch list. Update your local branch list from origin with:



                                                        git remote update


                                                        And then try checking out your remote branch again.



                                                        This worked for me.



                                                        I believe git fetch pulls in all remote branches, which is not what the original poster wanted.







                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited Jul 13 '14 at 23:12









                                                        Peter Mortensen

                                                        13.3k1983111




                                                        13.3k1983111










                                                        answered Jun 6 '13 at 12:21









                                                        webdevguy

                                                        800815




                                                        800815








                                                        • 2




                                                          FYI, git remote update will also fetch all remote branches.
                                                          – user456814
                                                          Jun 21 '14 at 17:59
















                                                        • 2




                                                          FYI, git remote update will also fetch all remote branches.
                                                          – user456814
                                                          Jun 21 '14 at 17:59










                                                        2




                                                        2




                                                        FYI, git remote update will also fetch all remote branches.
                                                        – user456814
                                                        Jun 21 '14 at 17:59






                                                        FYI, git remote update will also fetch all remote branches.
                                                        – user456814
                                                        Jun 21 '14 at 17:59












                                                        up vote
                                                        11
                                                        down vote













                                                        none of these answers worked for me. this worked:



                                                        git checkout -b feature/branch remotes/origin/feature/branch






                                                        share|improve this answer





















                                                        • thanks. I was wondering if I had to use the full path (remotes/origin/feature/branch) that I saw in git when calling git branch -a command, but I wasn't for sure, so I just used git checkout -b apps/FEATURE/branch origin/apps/FEATURE/branch and it appeared to work. Message: Branch 'apps/FEATURE/branch' set up to track remote branch 'apps/FEATURE/epicBranch' from 'origin'. Switched to a new branch 'apps/FEATURE/branch'
                                                          – Chris22
                                                          Jul 27 at 15:41

















                                                        up vote
                                                        11
                                                        down vote













                                                        none of these answers worked for me. this worked:



                                                        git checkout -b feature/branch remotes/origin/feature/branch






                                                        share|improve this answer





















                                                        • thanks. I was wondering if I had to use the full path (remotes/origin/feature/branch) that I saw in git when calling git branch -a command, but I wasn't for sure, so I just used git checkout -b apps/FEATURE/branch origin/apps/FEATURE/branch and it appeared to work. Message: Branch 'apps/FEATURE/branch' set up to track remote branch 'apps/FEATURE/epicBranch' from 'origin'. Switched to a new branch 'apps/FEATURE/branch'
                                                          – Chris22
                                                          Jul 27 at 15:41















                                                        up vote
                                                        11
                                                        down vote










                                                        up vote
                                                        11
                                                        down vote









                                                        none of these answers worked for me. this worked:



                                                        git checkout -b feature/branch remotes/origin/feature/branch






                                                        share|improve this answer












                                                        none of these answers worked for me. this worked:



                                                        git checkout -b feature/branch remotes/origin/feature/branch







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Jul 10 at 2:11









                                                        brianyang

                                                        434610




                                                        434610












                                                        • thanks. I was wondering if I had to use the full path (remotes/origin/feature/branch) that I saw in git when calling git branch -a command, but I wasn't for sure, so I just used git checkout -b apps/FEATURE/branch origin/apps/FEATURE/branch and it appeared to work. Message: Branch 'apps/FEATURE/branch' set up to track remote branch 'apps/FEATURE/epicBranch' from 'origin'. Switched to a new branch 'apps/FEATURE/branch'
                                                          – Chris22
                                                          Jul 27 at 15:41




















                                                        • thanks. I was wondering if I had to use the full path (remotes/origin/feature/branch) that I saw in git when calling git branch -a command, but I wasn't for sure, so I just used git checkout -b apps/FEATURE/branch origin/apps/FEATURE/branch and it appeared to work. Message: Branch 'apps/FEATURE/branch' set up to track remote branch 'apps/FEATURE/epicBranch' from 'origin'. Switched to a new branch 'apps/FEATURE/branch'
                                                          – Chris22
                                                          Jul 27 at 15:41


















                                                        thanks. I was wondering if I had to use the full path (remotes/origin/feature/branch) that I saw in git when calling git branch -a command, but I wasn't for sure, so I just used git checkout -b apps/FEATURE/branch origin/apps/FEATURE/branch and it appeared to work. Message: Branch 'apps/FEATURE/branch' set up to track remote branch 'apps/FEATURE/epicBranch' from 'origin'. Switched to a new branch 'apps/FEATURE/branch'
                                                        – Chris22
                                                        Jul 27 at 15:41






                                                        thanks. I was wondering if I had to use the full path (remotes/origin/feature/branch) that I saw in git when calling git branch -a command, but I wasn't for sure, so I just used git checkout -b apps/FEATURE/branch origin/apps/FEATURE/branch and it appeared to work. Message: Branch 'apps/FEATURE/branch' set up to track remote branch 'apps/FEATURE/epicBranch' from 'origin'. Switched to a new branch 'apps/FEATURE/branch'
                                                        – Chris22
                                                        Jul 27 at 15:41












                                                        up vote
                                                        10
                                                        down vote













                                                        The git remote show <origin name> command will list all branches (including un-tracked branches). Then you can find the remote branch name that you need to fetch.



                                                        Example:



                                                        $ git remote show origin


                                                        Use these steps to fetch remote branches:



                                                        git fetch <origin name> <remote branch name>:<local branch name>
                                                        git checkout <local branch name > (local branch name should the name that you given fetching)


                                                        Example:



                                                        $ git fetch origin test:test
                                                        $ git checkout test





                                                        share|improve this answer























                                                        • @hallski answered not working 2.15.1 versions but i have reduce .git file weigth clone only 1 branch and filter history with --depth flag. for example $ git clone -b release --single-branch --depth 5 https://github.com/user/repo.git Wron't information $ git remote show originthis does not listed all remote branch with single branch cloned repositories.
                                                          – Qh0stM4N
                                                          Jan 30 at 13:52















                                                        up vote
                                                        10
                                                        down vote













                                                        The git remote show <origin name> command will list all branches (including un-tracked branches). Then you can find the remote branch name that you need to fetch.



                                                        Example:



                                                        $ git remote show origin


                                                        Use these steps to fetch remote branches:



                                                        git fetch <origin name> <remote branch name>:<local branch name>
                                                        git checkout <local branch name > (local branch name should the name that you given fetching)


                                                        Example:



                                                        $ git fetch origin test:test
                                                        $ git checkout test





                                                        share|improve this answer























                                                        • @hallski answered not working 2.15.1 versions but i have reduce .git file weigth clone only 1 branch and filter history with --depth flag. for example $ git clone -b release --single-branch --depth 5 https://github.com/user/repo.git Wron't information $ git remote show originthis does not listed all remote branch with single branch cloned repositories.
                                                          – Qh0stM4N
                                                          Jan 30 at 13:52













                                                        up vote
                                                        10
                                                        down vote










                                                        up vote
                                                        10
                                                        down vote









                                                        The git remote show <origin name> command will list all branches (including un-tracked branches). Then you can find the remote branch name that you need to fetch.



                                                        Example:



                                                        $ git remote show origin


                                                        Use these steps to fetch remote branches:



                                                        git fetch <origin name> <remote branch name>:<local branch name>
                                                        git checkout <local branch name > (local branch name should the name that you given fetching)


                                                        Example:



                                                        $ git fetch origin test:test
                                                        $ git checkout test





                                                        share|improve this answer














                                                        The git remote show <origin name> command will list all branches (including un-tracked branches). Then you can find the remote branch name that you need to fetch.



                                                        Example:



                                                        $ git remote show origin


                                                        Use these steps to fetch remote branches:



                                                        git fetch <origin name> <remote branch name>:<local branch name>
                                                        git checkout <local branch name > (local branch name should the name that you given fetching)


                                                        Example:



                                                        $ git fetch origin test:test
                                                        $ git checkout test






                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited Mar 21 at 18:34









                                                        Peter Mortensen

                                                        13.3k1983111




                                                        13.3k1983111










                                                        answered Jan 7 at 13:12









                                                        Thushan

                                                        62578




                                                        62578












                                                        • @hallski answered not working 2.15.1 versions but i have reduce .git file weigth clone only 1 branch and filter history with --depth flag. for example $ git clone -b release --single-branch --depth 5 https://github.com/user/repo.git Wron't information $ git remote show originthis does not listed all remote branch with single branch cloned repositories.
                                                          – Qh0stM4N
                                                          Jan 30 at 13:52


















                                                        • @hallski answered not working 2.15.1 versions but i have reduce .git file weigth clone only 1 branch and filter history with --depth flag. for example $ git clone -b release --single-branch --depth 5 https://github.com/user/repo.git Wron't information $ git remote show originthis does not listed all remote branch with single branch cloned repositories.
                                                          – Qh0stM4N
                                                          Jan 30 at 13:52
















                                                        @hallski answered not working 2.15.1 versions but i have reduce .git file weigth clone only 1 branch and filter history with --depth flag. for example $ git clone -b release --single-branch --depth 5 https://github.com/user/repo.git Wron't information $ git remote show originthis does not listed all remote branch with single branch cloned repositories.
                                                        – Qh0stM4N
                                                        Jan 30 at 13:52




                                                        @hallski answered not working 2.15.1 versions but i have reduce .git file weigth clone only 1 branch and filter history with --depth flag. for example $ git clone -b release --single-branch --depth 5 https://github.com/user/repo.git Wron't information $ git remote show originthis does not listed all remote branch with single branch cloned repositories.
                                                        – Qh0stM4N
                                                        Jan 30 at 13:52










                                                        up vote
                                                        7
                                                        down vote













                                                        Other guys and gals give the solutions, but maybe I can tell you why.




                                                        git checkout test which does nothing




                                                        Does nothing doesn't equal doesn't work, so I guess when you type 'git checkout test' in your terminal and press enter key, no message appears and no error occurs. Am I right?



                                                        If the answer is 'yes', I can tell you the cause.



                                                        The cause is that there is a file (or folder) named 'test' in your work tree.



                                                        When git checkout xxx parsed,




                                                        1. Git looks on xxx as a branch name at first, but there isn't any branch named test.

                                                        2. Then Git thinks xxx is a path, and fortunately (or unfortunately), there is a file named test. So git checkout xxx means discard any modification in xxx file.

                                                        3. If there isn't file named xxx either, then Git will try to create the xxx according to some rules. One of the rules is create a branch named xxx if remotes/origin/xxx exists.






                                                        share|improve this answer



























                                                          up vote
                                                          7
                                                          down vote













                                                          Other guys and gals give the solutions, but maybe I can tell you why.




                                                          git checkout test which does nothing




                                                          Does nothing doesn't equal doesn't work, so I guess when you type 'git checkout test' in your terminal and press enter key, no message appears and no error occurs. Am I right?



                                                          If the answer is 'yes', I can tell you the cause.



                                                          The cause is that there is a file (or folder) named 'test' in your work tree.



                                                          When git checkout xxx parsed,




                                                          1. Git looks on xxx as a branch name at first, but there isn't any branch named test.

                                                          2. Then Git thinks xxx is a path, and fortunately (or unfortunately), there is a file named test. So git checkout xxx means discard any modification in xxx file.

                                                          3. If there isn't file named xxx either, then Git will try to create the xxx according to some rules. One of the rules is create a branch named xxx if remotes/origin/xxx exists.






                                                          share|improve this answer

























                                                            up vote
                                                            7
                                                            down vote










                                                            up vote
                                                            7
                                                            down vote









                                                            Other guys and gals give the solutions, but maybe I can tell you why.




                                                            git checkout test which does nothing




                                                            Does nothing doesn't equal doesn't work, so I guess when you type 'git checkout test' in your terminal and press enter key, no message appears and no error occurs. Am I right?



                                                            If the answer is 'yes', I can tell you the cause.



                                                            The cause is that there is a file (or folder) named 'test' in your work tree.



                                                            When git checkout xxx parsed,




                                                            1. Git looks on xxx as a branch name at first, but there isn't any branch named test.

                                                            2. Then Git thinks xxx is a path, and fortunately (or unfortunately), there is a file named test. So git checkout xxx means discard any modification in xxx file.

                                                            3. If there isn't file named xxx either, then Git will try to create the xxx according to some rules. One of the rules is create a branch named xxx if remotes/origin/xxx exists.






                                                            share|improve this answer














                                                            Other guys and gals give the solutions, but maybe I can tell you why.




                                                            git checkout test which does nothing




                                                            Does nothing doesn't equal doesn't work, so I guess when you type 'git checkout test' in your terminal and press enter key, no message appears and no error occurs. Am I right?



                                                            If the answer is 'yes', I can tell you the cause.



                                                            The cause is that there is a file (or folder) named 'test' in your work tree.



                                                            When git checkout xxx parsed,




                                                            1. Git looks on xxx as a branch name at first, but there isn't any branch named test.

                                                            2. Then Git thinks xxx is a path, and fortunately (or unfortunately), there is a file named test. So git checkout xxx means discard any modification in xxx file.

                                                            3. If there isn't file named xxx either, then Git will try to create the xxx according to some rules. One of the rules is create a branch named xxx if remotes/origin/xxx exists.







                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited Mar 21 at 18:39









                                                            Peter Mortensen

                                                            13.3k1983111




                                                            13.3k1983111










                                                            answered Jul 10 '17 at 7:45









                                                            oldman

                                                            3,64811514




                                                            3,64811514






















                                                                up vote
                                                                6
                                                                down vote













                                                                You can start tracking all remote branches with the following Bash script:



                                                                #!/bin/bash
                                                                git fetch --all
                                                                for branch in `git branch -r --format="%(refname:short)" | sed 's/origin///'`
                                                                do git branch -f --track "$branch" "origin/$branch"
                                                                done


                                                                Here is also a single-line version:



                                                                git fetch --all; for branch in `git branch -r --format="%(refname:short)" | sed 's/origin///'`; do git branch --track "$branch" "origin/$branch" ; done ;





                                                                share|improve this answer



























                                                                  up vote
                                                                  6
                                                                  down vote













                                                                  You can start tracking all remote branches with the following Bash script:



                                                                  #!/bin/bash
                                                                  git fetch --all
                                                                  for branch in `git branch -r --format="%(refname:short)" | sed 's/origin///'`
                                                                  do git branch -f --track "$branch" "origin/$branch"
                                                                  done


                                                                  Here is also a single-line version:



                                                                  git fetch --all; for branch in `git branch -r --format="%(refname:short)" | sed 's/origin///'`; do git branch --track "$branch" "origin/$branch" ; done ;





                                                                  share|improve this answer

























                                                                    up vote
                                                                    6
                                                                    down vote










                                                                    up vote
                                                                    6
                                                                    down vote









                                                                    You can start tracking all remote branches with the following Bash script:



                                                                    #!/bin/bash
                                                                    git fetch --all
                                                                    for branch in `git branch -r --format="%(refname:short)" | sed 's/origin///'`
                                                                    do git branch -f --track "$branch" "origin/$branch"
                                                                    done


                                                                    Here is also a single-line version:



                                                                    git fetch --all; for branch in `git branch -r --format="%(refname:short)" | sed 's/origin///'`; do git branch --track "$branch" "origin/$branch" ; done ;





                                                                    share|improve this answer














                                                                    You can start tracking all remote branches with the following Bash script:



                                                                    #!/bin/bash
                                                                    git fetch --all
                                                                    for branch in `git branch -r --format="%(refname:short)" | sed 's/origin///'`
                                                                    do git branch -f --track "$branch" "origin/$branch"
                                                                    done


                                                                    Here is also a single-line version:



                                                                    git fetch --all; for branch in `git branch -r --format="%(refname:short)" | sed 's/origin///'`; do git branch --track "$branch" "origin/$branch" ; done ;






                                                                    share|improve this answer














                                                                    share|improve this answer



                                                                    share|improve this answer








                                                                    edited Mar 21 at 18:37









                                                                    Peter Mortensen

                                                                    13.3k1983111




                                                                    13.3k1983111










                                                                    answered Aug 11 '17 at 12:06









                                                                    OzzyCzech

                                                                    4,95613225




                                                                    4,95613225






















                                                                        up vote
                                                                        5
                                                                        down vote













                                                                        To get newly created branches



                                                                        git fetch


                                                                        To switch into another branch



                                                                        git checkout BranchName





                                                                        share|improve this answer



























                                                                          up vote
                                                                          5
                                                                          down vote













                                                                          To get newly created branches



                                                                          git fetch


                                                                          To switch into another branch



                                                                          git checkout BranchName





                                                                          share|improve this answer

























                                                                            up vote
                                                                            5
                                                                            down vote










                                                                            up vote
                                                                            5
                                                                            down vote









                                                                            To get newly created branches



                                                                            git fetch


                                                                            To switch into another branch



                                                                            git checkout BranchName





                                                                            share|improve this answer














                                                                            To get newly created branches



                                                                            git fetch


                                                                            To switch into another branch



                                                                            git checkout BranchName






                                                                            share|improve this answer














                                                                            share|improve this answer



                                                                            share|improve this answer








                                                                            edited Jul 7 at 3:59









                                                                            Community

                                                                            11




                                                                            11










                                                                            answered Mar 15 at 8:49









                                                                            Hasib Kamal

                                                                            651617




                                                                            651617






















                                                                                up vote
                                                                                4
                                                                                down vote













                                                                                Simply run git checkout with the name of the remote branch. Git will automatically create a local branch that tracks the remote one:



                                                                                git fetch
                                                                                git checkout test


                                                                                However, if that branch name is found in more than one remote, this won't work as Git doesn't know which to use. In that case you can use either:



                                                                                git checkout --track origin/test


                                                                                or



                                                                                git checkout -b test origin/test


                                                                                In 2.19, Git learned the checkout.defaultRemote configuration, which specifies a remote to default to when resolving such an ambiguity.






                                                                                share|improve this answer

























                                                                                  up vote
                                                                                  4
                                                                                  down vote













                                                                                  Simply run git checkout with the name of the remote branch. Git will automatically create a local branch that tracks the remote one:



                                                                                  git fetch
                                                                                  git checkout test


                                                                                  However, if that branch name is found in more than one remote, this won't work as Git doesn't know which to use. In that case you can use either:



                                                                                  git checkout --track origin/test


                                                                                  or



                                                                                  git checkout -b test origin/test


                                                                                  In 2.19, Git learned the checkout.defaultRemote configuration, which specifies a remote to default to when resolving such an ambiguity.






                                                                                  share|improve this answer























                                                                                    up vote
                                                                                    4
                                                                                    down vote










                                                                                    up vote
                                                                                    4
                                                                                    down vote









                                                                                    Simply run git checkout with the name of the remote branch. Git will automatically create a local branch that tracks the remote one:



                                                                                    git fetch
                                                                                    git checkout test


                                                                                    However, if that branch name is found in more than one remote, this won't work as Git doesn't know which to use. In that case you can use either:



                                                                                    git checkout --track origin/test


                                                                                    or



                                                                                    git checkout -b test origin/test


                                                                                    In 2.19, Git learned the checkout.defaultRemote configuration, which specifies a remote to default to when resolving such an ambiguity.






                                                                                    share|improve this answer












                                                                                    Simply run git checkout with the name of the remote branch. Git will automatically create a local branch that tracks the remote one:



                                                                                    git fetch
                                                                                    git checkout test


                                                                                    However, if that branch name is found in more than one remote, this won't work as Git doesn't know which to use. In that case you can use either:



                                                                                    git checkout --track origin/test


                                                                                    or



                                                                                    git checkout -b test origin/test


                                                                                    In 2.19, Git learned the checkout.defaultRemote configuration, which specifies a remote to default to when resolving such an ambiguity.







                                                                                    share|improve this answer












                                                                                    share|improve this answer



                                                                                    share|improve this answer










                                                                                    answered Sep 13 at 12:21









                                                                                    Eugene Yarmash

                                                                                    81.6k22172257




                                                                                    81.6k22172257






















                                                                                        up vote
                                                                                        2
                                                                                        down vote













                                                                                        Please follow the command to create an empty folder. Enter that and use this command:



                                                                                        saifurs-Mini:YO-iOS saifurrahman$ git clone your_project_url
                                                                                        Cloning into 'iPhoneV1'...
                                                                                        remote: Counting objects: 34230, done.
                                                                                        remote: Compressing objects: 100% (24028/24028), done.
                                                                                        remote: Total 34230 (delta 22212), reused 15340 (delta 9324)
                                                                                        Receiving objects: 100% (34230/34230), 202.53 MiB | 294.00 KiB/s, done.
                                                                                        Resolving deltas: 100% (22212/22212), done.
                                                                                        Checking connectivity... done.
                                                                                        saifurs-Mini:YO-iOS saifurrahman$ cd iPhoneV1/
                                                                                        saifurs-Mini:iPhoneV1 saifurrahman$ git checkout 1_4_0_content_discovery
                                                                                        Branch 1_4_0_content_discovery set up to track remote branch 1_4_0_content_discovery from origin.
                                                                                        Switched to a new branch '1_4_0_content_discovery'





                                                                                        share|improve this answer



























                                                                                          up vote
                                                                                          2
                                                                                          down vote













                                                                                          Please follow the command to create an empty folder. Enter that and use this command:



                                                                                          saifurs-Mini:YO-iOS saifurrahman$ git clone your_project_url
                                                                                          Cloning into 'iPhoneV1'...
                                                                                          remote: Counting objects: 34230, done.
                                                                                          remote: Compressing objects: 100% (24028/24028), done.
                                                                                          remote: Total 34230 (delta 22212), reused 15340 (delta 9324)
                                                                                          Receiving objects: 100% (34230/34230), 202.53 MiB | 294.00 KiB/s, done.
                                                                                          Resolving deltas: 100% (22212/22212), done.
                                                                                          Checking connectivity... done.
                                                                                          saifurs-Mini:YO-iOS saifurrahman$ cd iPhoneV1/
                                                                                          saifurs-Mini:iPhoneV1 saifurrahman$ git checkout 1_4_0_content_discovery
                                                                                          Branch 1_4_0_content_discovery set up to track remote branch 1_4_0_content_discovery from origin.
                                                                                          Switched to a new branch '1_4_0_content_discovery'





                                                                                          share|improve this answer

























                                                                                            up vote
                                                                                            2
                                                                                            down vote










                                                                                            up vote
                                                                                            2
                                                                                            down vote









                                                                                            Please follow the command to create an empty folder. Enter that and use this command:



                                                                                            saifurs-Mini:YO-iOS saifurrahman$ git clone your_project_url
                                                                                            Cloning into 'iPhoneV1'...
                                                                                            remote: Counting objects: 34230, done.
                                                                                            remote: Compressing objects: 100% (24028/24028), done.
                                                                                            remote: Total 34230 (delta 22212), reused 15340 (delta 9324)
                                                                                            Receiving objects: 100% (34230/34230), 202.53 MiB | 294.00 KiB/s, done.
                                                                                            Resolving deltas: 100% (22212/22212), done.
                                                                                            Checking connectivity... done.
                                                                                            saifurs-Mini:YO-iOS saifurrahman$ cd iPhoneV1/
                                                                                            saifurs-Mini:iPhoneV1 saifurrahman$ git checkout 1_4_0_content_discovery
                                                                                            Branch 1_4_0_content_discovery set up to track remote branch 1_4_0_content_discovery from origin.
                                                                                            Switched to a new branch '1_4_0_content_discovery'





                                                                                            share|improve this answer














                                                                                            Please follow the command to create an empty folder. Enter that and use this command:



                                                                                            saifurs-Mini:YO-iOS saifurrahman$ git clone your_project_url
                                                                                            Cloning into 'iPhoneV1'...
                                                                                            remote: Counting objects: 34230, done.
                                                                                            remote: Compressing objects: 100% (24028/24028), done.
                                                                                            remote: Total 34230 (delta 22212), reused 15340 (delta 9324)
                                                                                            Receiving objects: 100% (34230/34230), 202.53 MiB | 294.00 KiB/s, done.
                                                                                            Resolving deltas: 100% (22212/22212), done.
                                                                                            Checking connectivity... done.
                                                                                            saifurs-Mini:YO-iOS saifurrahman$ cd iPhoneV1/
                                                                                            saifurs-Mini:iPhoneV1 saifurrahman$ git checkout 1_4_0_content_discovery
                                                                                            Branch 1_4_0_content_discovery set up to track remote branch 1_4_0_content_discovery from origin.
                                                                                            Switched to a new branch '1_4_0_content_discovery'






                                                                                            share|improve this answer














                                                                                            share|improve this answer



                                                                                            share|improve this answer








                                                                                            edited Jun 30 '16 at 16:09









                                                                                            Peter Mortensen

                                                                                            13.3k1983111




                                                                                            13.3k1983111










                                                                                            answered Jan 1 '16 at 10:31









                                                                                            Mehedi Hasan

                                                                                            13018




                                                                                            13018






















                                                                                                up vote
                                                                                                2
                                                                                                down vote













                                                                                                I was stuck in a situation seeing error: pathspec 'desired-branch' did not match any file(s) known to git. for all of the suggestions above. I'm on git version 1.8.3.1.



                                                                                                So this worked for me:



                                                                                                git fetch origin desired-branch
                                                                                                git checkout -b desired-branch FETCH_HEAD


                                                                                                The explanation behind is that I've noticed that when fetching the remote branch, it was fetched to FETCH_HEAD:



                                                                                                $ git fetch origin desired-branch
                                                                                                From github.com:MYTEAM/my-repo
                                                                                                * branch desired-branch -> FETCH_HEAD





                                                                                                share|improve this answer

























                                                                                                  up vote
                                                                                                  2
                                                                                                  down vote













                                                                                                  I was stuck in a situation seeing error: pathspec 'desired-branch' did not match any file(s) known to git. for all of the suggestions above. I'm on git version 1.8.3.1.



                                                                                                  So this worked for me:



                                                                                                  git fetch origin desired-branch
                                                                                                  git checkout -b desired-branch FETCH_HEAD


                                                                                                  The explanation behind is that I've noticed that when fetching the remote branch, it was fetched to FETCH_HEAD:



                                                                                                  $ git fetch origin desired-branch
                                                                                                  From github.com:MYTEAM/my-repo
                                                                                                  * branch desired-branch -> FETCH_HEAD





                                                                                                  share|improve this answer























                                                                                                    up vote
                                                                                                    2
                                                                                                    down vote










                                                                                                    up vote
                                                                                                    2
                                                                                                    down vote









                                                                                                    I was stuck in a situation seeing error: pathspec 'desired-branch' did not match any file(s) known to git. for all of the suggestions above. I'm on git version 1.8.3.1.



                                                                                                    So this worked for me:



                                                                                                    git fetch origin desired-branch
                                                                                                    git checkout -b desired-branch FETCH_HEAD


                                                                                                    The explanation behind is that I've noticed that when fetching the remote branch, it was fetched to FETCH_HEAD:



                                                                                                    $ git fetch origin desired-branch
                                                                                                    From github.com:MYTEAM/my-repo
                                                                                                    * branch desired-branch -> FETCH_HEAD





                                                                                                    share|improve this answer












                                                                                                    I was stuck in a situation seeing error: pathspec 'desired-branch' did not match any file(s) known to git. for all of the suggestions above. I'm on git version 1.8.3.1.



                                                                                                    So this worked for me:



                                                                                                    git fetch origin desired-branch
                                                                                                    git checkout -b desired-branch FETCH_HEAD


                                                                                                    The explanation behind is that I've noticed that when fetching the remote branch, it was fetched to FETCH_HEAD:



                                                                                                    $ git fetch origin desired-branch
                                                                                                    From github.com:MYTEAM/my-repo
                                                                                                    * branch desired-branch -> FETCH_HEAD






                                                                                                    share|improve this answer












                                                                                                    share|improve this answer



                                                                                                    share|improve this answer










                                                                                                    answered Oct 10 at 21:52









                                                                                                    alisa

                                                                                                    4061613




                                                                                                    4061613






















                                                                                                        up vote
                                                                                                        1
                                                                                                        down vote













                                                                                                        Fetch origin and checkout the branch.



                                                                                                        git fetch origin && git checkout branch_name 





                                                                                                        share|improve this answer



























                                                                                                          up vote
                                                                                                          1
                                                                                                          down vote













                                                                                                          Fetch origin and checkout the branch.



                                                                                                          git fetch origin && git checkout branch_name 





                                                                                                          share|improve this answer

























                                                                                                            up vote
                                                                                                            1
                                                                                                            down vote










                                                                                                            up vote
                                                                                                            1
                                                                                                            down vote









                                                                                                            Fetch origin and checkout the branch.



                                                                                                            git fetch origin && git checkout branch_name 





                                                                                                            share|improve this answer














                                                                                                            Fetch origin and checkout the branch.



                                                                                                            git fetch origin && git checkout branch_name 






                                                                                                            share|improve this answer














                                                                                                            share|improve this answer



                                                                                                            share|improve this answer








                                                                                                            edited May 21 at 12:57

























                                                                                                            answered May 21 at 11:33









                                                                                                            Pranav

                                                                                                            493412




                                                                                                            493412






















                                                                                                                up vote
                                                                                                                0
                                                                                                                down vote













                                                                                                                If the remote branch name begins with special characteres you need to use single quotes around it in the checkout command, or else git won't know which branch you are talking about.



                                                                                                                For example, I tried to checkout a remote branch named as #9773 but the command didn't work properly, as shown in the picture below:



                                                                                                                enter image description here



                                                                                                                For some reason I wondered if the sharp symbol (#) could have something to do with it, and then I tried surrounding the branch name with single quotes, like '#9773' rathen than just #9773, and it worked fine.



                                                                                                                $ git checkout -b '#9773' origin/'#9773'





                                                                                                                share|improve this answer





















                                                                                                                • In many unix shells the # character is used for comments so anything after the # will be ignored. This is a shell thing and not something specific to git. Using quotes of a backslash before the # should be enough.
                                                                                                                  – Paulo Scardine
                                                                                                                  Nov 7 at 12:12















                                                                                                                up vote
                                                                                                                0
                                                                                                                down vote













                                                                                                                If the remote branch name begins with special characteres you need to use single quotes around it in the checkout command, or else git won't know which branch you are talking about.



                                                                                                                For example, I tried to checkout a remote branch named as #9773 but the command didn't work properly, as shown in the picture below:



                                                                                                                enter image description here



                                                                                                                For some reason I wondered if the sharp symbol (#) could have something to do with it, and then I tried surrounding the branch name with single quotes, like '#9773' rathen than just #9773, and it worked fine.



                                                                                                                $ git checkout -b '#9773' origin/'#9773'





                                                                                                                share|improve this answer





















                                                                                                                • In many unix shells the # character is used for comments so anything after the # will be ignored. This is a shell thing and not something specific to git. Using quotes of a backslash before the # should be enough.
                                                                                                                  – Paulo Scardine
                                                                                                                  Nov 7 at 12:12













                                                                                                                up vote
                                                                                                                0
                                                                                                                down vote










                                                                                                                up vote
                                                                                                                0
                                                                                                                down vote









                                                                                                                If the remote branch name begins with special characteres you need to use single quotes around it in the checkout command, or else git won't know which branch you are talking about.



                                                                                                                For example, I tried to checkout a remote branch named as #9773 but the command didn't work properly, as shown in the picture below:



                                                                                                                enter image description here



                                                                                                                For some reason I wondered if the sharp symbol (#) could have something to do with it, and then I tried surrounding the branch name with single quotes, like '#9773' rathen than just #9773, and it worked fine.



                                                                                                                $ git checkout -b '#9773' origin/'#9773'





                                                                                                                share|improve this answer












                                                                                                                If the remote branch name begins with special characteres you need to use single quotes around it in the checkout command, or else git won't know which branch you are talking about.



                                                                                                                For example, I tried to checkout a remote branch named as #9773 but the command didn't work properly, as shown in the picture below:



                                                                                                                enter image description here



                                                                                                                For some reason I wondered if the sharp symbol (#) could have something to do with it, and then I tried surrounding the branch name with single quotes, like '#9773' rathen than just #9773, and it worked fine.



                                                                                                                $ git checkout -b '#9773' origin/'#9773'






                                                                                                                share|improve this answer












                                                                                                                share|improve this answer



                                                                                                                share|improve this answer










                                                                                                                answered Nov 7 at 11:17









                                                                                                                Ulysses Alves

                                                                                                                1,20011023




                                                                                                                1,20011023












                                                                                                                • In many unix shells the # character is used for comments so anything after the # will be ignored. This is a shell thing and not something specific to git. Using quotes of a backslash before the # should be enough.
                                                                                                                  – Paulo Scardine
                                                                                                                  Nov 7 at 12:12


















                                                                                                                • In many unix shells the # character is used for comments so anything after the # will be ignored. This is a shell thing and not something specific to git. Using quotes of a backslash before the # should be enough.
                                                                                                                  – Paulo Scardine
                                                                                                                  Nov 7 at 12:12
















                                                                                                                In many unix shells the # character is used for comments so anything after the # will be ignored. This is a shell thing and not something specific to git. Using quotes of a backslash before the # should be enough.
                                                                                                                – Paulo Scardine
                                                                                                                Nov 7 at 12:12




                                                                                                                In many unix shells the # character is used for comments so anything after the # will be ignored. This is a shell thing and not something specific to git. Using quotes of a backslash before the # should be enough.
                                                                                                                – Paulo Scardine
                                                                                                                Nov 7 at 12:12





                                                                                                                protected by Praveen May 9 '13 at 10:07



                                                                                                                Thank you for your interest in this question.
                                                                                                                Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                                                                                Would you like to answer one of these unanswered questions instead?



                                                                                                                這個網誌中的熱門文章

                                                                                                                Tangent Lines Diagram Along Smooth Curve

                                                                                                                Yusuf al-Mu'taman ibn Hud

                                                                                                                Zucchini