<p>My <code>master</code> and <code>development</code> branches are tracked remotely on <a href="http://en.wikipedia.org/wiki/GitHub" rel="noreferrer">GitHub</a>. How do I clone both these branches?</p>

[{'answer_id': 67712, 'author': 'MattoxBeckman', 'author_id': 10354, 'author_profile': 'https://Stackoverflow.com/users/10354', 'pm_score': 5, 'selected': False, 'text': '<p>A <code>git clone</code> is supposed to copy the entire repository.  Try cloning it, and then run <code>git branch -a</code>.  It should list all the branches.  If then you want to switch to branch "foo" instead of "master", use <code>git checkout foo</code>.</p>\n'}, {'answer_id': 67716, 'author': 'elmarco', 'author_id': 1277510, 'author_profile': 'https://Stackoverflow.com/users/1277510', 'pm_score': 6, 'selected': False, 'text': '<p>When you do "git clone git://location", all branches and tags are fetched.</p>\n\n<p>In order to work on top of a specific remote branch, assuming it\'s the origin remote:</p>\n\n<pre><code>git checkout -b branch origin/branchname\n</code></pre>\n'}, {'answer_id': 67748, 'author': 'Luuk Paulussen', 'author_id': 10394, 'author_profile': 'https://Stackoverflow.com/users/10394', 'pm_score': 6, 'selected': False, 'text': '<p>The fetch that you are doing should get all the remote branches, but it won\'t create local branches for them. If you use <a href="https://git-scm.com/docs/gitk" rel="nofollow noreferrer">gitk</a>, you should see the remote branches described as &quot;remotes/origin/dev&quot; or something similar.</p>\n<p>To create a local branch based on a remote branch, do something like:</p>\n<pre><code>git checkout -b dev refs/remotes/origin/dev\n</code></pre>\n<p>Which should return something like:</p>\n<pre><code>Branch dev set up to track remote branch refs/remotes/origin/dev. Switched to a new branch &quot;dev&quot;\n</code></pre>\n<p>Now, when you are on the <em>dev</em> branch, &quot;git pull&quot; will update your local <em>dev</em> to the same point as the remote <em>dev</em> branch.  Note that it will fetch all branches, but only pull the one you are on to the top of the tree.</p>\n'}, {'answer_id': 72156, 'author': 'emk', 'author_id': 12089, 'author_profile': 'https://Stackoverflow.com/users/12089', 'pm_score': 13, 'selected': True, 'text': '<p>First, clone a remote <a href="http://en.wikipedia.org/wiki/Git_%28software%29" rel="noreferrer">Git</a> repository and <a href="http://en.wikipedia.org/wiki/Cd_%28command%29" rel="noreferrer"><code>cd</code></a> into it:</p>\n<pre><code>$ git clone git://example.com/myproject\n$ cd myproject\n</code></pre>\n<p>Next, look at the local branches in your repository:</p>\n<pre><code>$ git branch\n* master\n</code></pre>\n<p>But there are other branches hiding in your repository! See these using the <code>-a</code> flag:</p>\n<pre><code>$ git branch -a\n* master\n  remotes/origin/HEAD\n  remotes/origin/master\n  remotes/origin/v1.0-stable\n  remotes/origin/experimental\n</code></pre>\n<p>To take a quick peek at an upstream branch, check it out directly:</p>\n<pre><code>$ git checkout origin/experimental\n</code></pre>\n<p>To work on that branch, create a local tracking branch, which is done automatically by:</p>\n<pre><code>$ git checkout experimental\n\nBranch experimental set up to track remote branch experimental from origin.\nSwitched to a new branch \'experimental\'\n</code></pre>\n<p>Here, &quot;new branch&quot; simply means that the branch is taken from the index and created locally for you.  As the <em>previous</em> line tells you, the branch is being set up to track the remote branch, which usually means the origin/branch_name branch.</p>\n<p>Your local branches should now show:</p>\n<pre><code>$ git branch\n* experimental\n  master\n</code></pre>\n<p>You can track more than one remote repository using <code>git remote</code>:</p>\n<pre><code>$ git remote add win32 git://example.com/users/joe/myproject-win32-port\n$ git branch -a\n* master\n  remotes/origin/HEAD\n  remotes/origin/master\n  remotes/origin/v1.0-stable\n  remotes/origin/experimental\n  remotes/win32/master\n  remotes/win32/new-widgets\n</code></pre>\n<p>At this point, things are getting pretty crazy, so run <code>gitk</code> to see what\'s going on:</p>\n<pre><code>$ gitk --all &amp;\n</code></pre>\n'}, {'answer_id': 108203, 'author': 'webmat', 'author_id': 6349, 'author_profile': 'https://Stackoverflow.com/users/6349', 'pm_score': 4, 'selected': False, 'text': '<p>Use my tool <a href="http://programblings.com/2008/08/06/time-to-git-collaborating-with-git_remote_branch/" rel="nofollow noreferrer">git_remote_branch</a> (<em>grb</em>). You need <a href="https://en.wikipedia.org/wiki/Ruby_%28programming_language%29" rel="nofollow noreferrer">Ruby</a> installed on your machine). It\'s built specifically to make remote branch manipulations dead easy.</p>\n<p>Each time it does an operation on your behalf, it prints it in red at the console. Over time, they finally stick into your brain :-)</p>\n<p>If you don\'t want grb to run commands on your behalf, just use the \'explain\' feature. The commands will be printed to your console instead of executed for you.</p>\n<p>Finally, all commands have aliases, to make memorization easier.</p>\n<p>Note that this is <a href="http://programblings.com/2008/08/06/time-to-git-collaborating-with-git_remote_branch/" rel="nofollow noreferrer">alpha software</a> ;-)</p>\n<p>Here\'s the help when you run grb help:</p>\n<pre>\ngit_remote_branch version 0.2.6\n\n  Usage:\n\n  grb create branch_name [origin_server]\n\n  grb publish branch_name [origin_server]\n\n  grb rename branch_name [origin_server]\n\n  grb delete branch_name [origin_server]\n\n  grb track branch_name [origin_server]\n\n\n\n  Notes:\n  - If origin_server is not specified, the name \'origin\' is assumed\n    (git\'s default)\n  - The rename functionality renames the current branch\n\n  The explain meta-command: you can also prepend any command with the\nkeyword \'explain\'. Instead of executing the command, git_remote_branch\nwill simply output the list of commands you need to run to accomplish\nthat goal.\n\n  Example:\n    grb explain create\n    grb explain create my_branch github\n\n  All commands also have aliases:\n  create: create, new\n  delete: delete, destroy, kill, remove, rm\n  publish: publish, remotize\n  rename: rename, rn, mv, move\n  track: track, follow, grab, fetch\n</pre>\n'}, {'answer_id': 1186645, 'author': 'murphytalk', 'author_id': 144330, 'author_profile': 'https://Stackoverflow.com/users/144330', 'pm_score': 7, 'selected': False, 'text': '<p>Regarding,</p>\n<blockquote>\n<p>git checkout -b experimental origin/experimental</p>\n</blockquote>\n<p>using</p>\n<pre><code>git checkout -t origin/experimental\n</code></pre>\n<p>or the more verbose, but easier to remember</p>\n<pre><code>git checkout --track origin/experimental\n</code></pre>\n<p>might be better, in terms of tracking a remote repository.</p>\n'}, {'answer_id': 4414131, 'author': 'user43685', 'author_id': 43685, 'author_profile': 'https://Stackoverflow.com/users/43685', 'pm_score': 3, 'selected': False, 'text': '<p>I needed to do exactly the same. Here is my <a href="http://en.wikipedia.org/wiki/Ruby_%28programming_language%29" rel="nofollow">Ruby</a> script.</p>\n\n<pre><code>#!/usr/bin/env ruby\n\nlocal = []\nremote = {}\n\n# Prepare\n%x[git reset --hard HEAD]\n%x[git checkout master] # Makes sure that * is on master.\n%x[git branch -a].each_line do |line|\n  line.strip!\n  if /origin\\//.match(line)\n     remote[line.gsub(/origin\\//, \'\')] = line\n   else\n     local &lt;&lt; line\n   end\nend\n# Update \nremote.each_pair do |loc, rem|\n  next if local.include?(loc)\n  %x[git checkout --track -b #{loc} #{rem}]\nend\n%x[git fetch]\n</code></pre>\n'}, {'answer_id': 4682612, 'author': 'Gabe Kopley', 'author_id': 283398, 'author_profile': 'https://Stackoverflow.com/users/283398', 'pm_score': 10, 'selected': False, 'text': '<p>If you have many remote branches that you want to fetch at once, do:</p>\n<pre><code>git pull --all\n</code></pre>\n<p>Now you can checkout any branch as you need to, without hitting the remote repository.</p>\n<hr />\n<p><strong>Note:</strong> This will not create working copies of any non-checked out branches, which is what the question was asking. For that, see</p>\n<ul>\n<li><a href="https://stackoverflow.com/questions/67699/how-to-clone-all-remote-branches-in-git/4754797#4754797">bigfish\'s answer</a></li>\n<li><a href="https://stackoverflow.com/questions/67699/how-to-clone-all-remote-branches-in-git/7216269#7216269">Dave\'s answer</a></li>\n</ul>\n'}, {'answer_id': 4754797, 'author': 'bigfish', 'author_id': 583867, 'author_profile': 'https://Stackoverflow.com/users/583867', 'pm_score': 9, 'selected': False, 'text': '<p>This <a href="http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29" rel="noreferrer">Bash</a> script helped me out:</p>\n\n<pre><code>#!/bin/bash\nfor branch in $(git branch --all | grep \'^\\s*remotes\' | egrep --invert-match \'(:?HEAD|master)$\'); do\n    git branch --track "${branch##*/}" "$branch"\ndone\n</code></pre>\n\n<p>It will create tracking branches for all remote branches, except master (which you probably got from the original clone command). I think you might still need to do a </p>\n\n<pre><code>git fetch --all\ngit pull --all\n</code></pre>\n\n<p>to be sure.</p>\n\n<blockquote>\n  <p><strong>One liner</strong>: <code>git branch -a | grep -v HEAD | perl -ne \'chomp($_); s|^\\*?\\s*||; if (m|(.+)/(.+)| &amp;&amp; not $d{$2}) {print qq(git branch --track $2 $1/$2\\n)} else {$d{$_}=1}\' | csh -xfs</code><br>\n  As usual: test in your setup before copying rm -rf universe as we know it </p>\n  \n  <p><em>Credits for one-liner go to user cfi</em></p>\n</blockquote>\n'}, {'answer_id': 6186997, 'author': 'rapher', 'author_id': 777553, 'author_profile': 'https://Stackoverflow.com/users/777553', 'pm_score': 5, 'selected': False, 'text': "<p>Just do this:</p>\n<pre><code>$ git clone git://example.com/myproject\n\n$ cd myproject\n\n$ git checkout branchxyz\nBranch branchxyz set up to track remote branch branchxyz from origin.\nSwitched to a new branch 'branchxyz'\n\n$ git pull\nAlready up-to-date.\n\n$ git branch\n* branchxyz\n  master\n\n$ git branch -a\n* branchxyz\n  master\n  remotes/origin/HEAD -&gt; origin/master\n  remotes/origin/branchxyz\n  remotes/origin/branch123\n</code></pre>\n<p>You see, <code>git clone git://example.com/myprojectt</code> fetches everything, even the branches, you just have to checkout them, then your local branch will be created.</p>\n"}, {'answer_id': 7216269, 'author': 'Dave', 'author_id': 915724, 'author_profile': 'https://Stackoverflow.com/users/915724', 'pm_score': 9, 'selected': False, 'text': '<p>Using the <code>--mirror</code> option seems to copy the <code>remote</code> tracking branches properly.\nHowever, it sets up the repository as a bare repository, so you have to turn it back into a normal repository afterwards.</p>\n\n<pre><code>git clone --mirror path/to/original path/to/dest/.git\ncd path/to/dest\ngit config --bool core.bare false\ngit checkout anybranch\n</code></pre>\n\n<p><sup>Reference: <a href="https://git.wiki.kernel.org/index.php/Git_FAQ#How_do_I_clone_a_repository_with_all_remotely_tracked_branches.3F" rel="noreferrer">Git FAQ: How do I clone a repository with all remotely tracked branches? </a></sup></p>\n'}, {'answer_id': 10563611, 'author': 'Nikos C.', 'author_id': 856199, 'author_profile': 'https://Stackoverflow.com/users/856199', 'pm_score': 8, 'selected': False, 'text': "<p>You can easily switch to a branch without using the fancy &quot;git checkout -b somebranch origin/somebranch&quot; syntax.  You can do:</p>\n<pre><code>git checkout somebranch\n</code></pre>\n<p>Git will automatically do the right thing:</p>\n<pre><code>$ git checkout somebranch\nBranch somebranch set up to track remote branch somebranch from origin.\nSwitched to a new branch 'somebranch'\n</code></pre>\n<p>Git will check whether a branch with the same name exists in exactly one remote, and if it does, it tracks it the same way as if you had explicitly specified that it's a remote branch. From the git-checkout man page of Git 1.8.2.1:</p>\n<blockquote>\n<p>If &lt;branch&gt; is not found but there does exist a tracking branch in\nexactly one remote (call it &lt;remote&gt;) with a matching name, treat as\nequivalent to</p>\n<pre><code>$ git checkout -b &lt;branch&gt; --track &lt;remote&gt;/&lt;branch&gt;\n</code></pre>\n</blockquote>\n"}, {'answer_id': 12389954, 'author': 'Andy', 'author_id': 312480, 'author_profile': 'https://Stackoverflow.com/users/312480', 'pm_score': 2, 'selected': False, 'text': '<p>I think this does the trick:</p>\n<pre><code>mkdir YourRepo\ncd YourRepo\ngit init --bare .git                       # create a bare repo\ngit remote add origin REMOTE_URL           # add a remote\ngit fetch origin refs/heads/*:refs/heads/* # fetch heads\ngit fetch origin refs/tags/*:refs/tags/*   # fetch tags\ngit init                                   # reinit work tree\ngit checkout master                        # checkout a branch\n</code></pre>\n<p>So far, this works for me.</p>\n'}, {'answer_id': 13575102, 'author': 'Jacob Fike', 'author_id': 506537, 'author_profile': 'https://Stackoverflow.com/users/506537', 'pm_score': 6, 'selected': False, 'text': '<p>Here is the best way to do this:</p>\n<pre><code>mkdir repo\ncd repo\ngit clone --bare path/to/repo.git .git\ngit config --unset core.bare\ngit reset --hard\n</code></pre>\n<p>At this point you have a complete copy of the remote repository with all of its branches (verify with <code>git branch</code>).  You can use <code>--mirror</code> instead of <code>--bare</code> if your remote repository has remotes of its own.</p>\n'}, {'answer_id': 16563327, 'author': 'nobody', 'author_id': 2383918, 'author_profile': 'https://Stackoverflow.com/users/2383918', 'pm_score': 6, 'selected': False, 'text': '<p>Use aliases. Though there aren\'t any native Git one-liners, you can define your own as</p>\n\n<pre><code>git config --global alias.clone-branches \'! git branch -a | sed -n "/\\/HEAD /d; /\\/master$/d; /remotes/p;" | xargs -L1 git checkout -t\'\n</code></pre>\n\n<p>and then use it as</p>\n\n<pre><code>git clone-branches\n</code></pre>\n'}, {'answer_id': 17635744, 'author': 'Camwyn', 'author_id': 813905, 'author_profile': 'https://Stackoverflow.com/users/813905', 'pm_score': 2, 'selected': False, 'text': "<p>I was trying to find out how to pull down a remote branch I had deleted locally. Origin was not mine, and I didn't want to go through the hassle of re-cloning everything.</p>\n<p>This worked for me:</p>\n<p>assuming you need to recreate the branch locally:</p>\n<pre><code>git checkout -b recreated-branch-name\ngit branch -a (to list remote branches)\ngit rebase remotes/remote-origin/recreated-branch-name\n</code></pre>\n<p>So if I forked from <em>gituser/master</em> to <em>sjp</em> and then branched it to <em>sjp/mynewbranch</em>, it would look like this:</p>\n<pre><code>$ git checkout -b mynewbranch\n\n$ git branch -a\n  master\n  remotes/sjp/master\n  remotes/sjp/mynewbranch\n\n$ git fetch (habit to always do before)\n\n$ git rebase remotes/sjp/mynewbranch\n</code></pre>\n"}, {'answer_id': 20697765, 'author': 'ikaruss', 'author_id': 1998046, 'author_profile': 'https://Stackoverflow.com/users/1998046', 'pm_score': 3, 'selected': False, 'text': '<p>For copy-pasting into the command line:</p>\n<pre><code>git checkout master ; remote=origin ; for brname in `git branch -r | grep $remote | grep -v master | grep -v HEAD | awk \'{gsub(/^[^\\/]+\\//,&quot;&quot;,$1); print $1}\'`; do git branch -D $brname ; git checkout -b $brname $remote/$brname ; done ; git checkout master\n</code></pre>\n<p>For higher readability:</p>\n<pre><code>git checkout master ;\nremote=origin ;\nfor brname in `\n    git branch -r | grep $remote | grep -v master | grep -v HEAD\n    | awk \'{gsub(/^[^\\/]+\\//,&quot;&quot;,$1); print $1}\'\n`; do\n    git branch -D $brname ;\n    git checkout -b $brname $remote/$brname ;\ndone ;\ngit checkout master\n</code></pre>\n<hr>\n<p>This will:</p>\n<ol>\n<li>check out master (so that we can delete branch we are on)</li>\n<li><strong>select remote</strong> to checkout (change it to whatever remote you have)</li>\n<li><strong>loop through all branches</strong> of the remote except master and HEAD\n0. <strong>delete</strong> local branch (so that we can check out force-updated branches)\n0. <strong>check out</strong> branch from the remote</li>\n<li>check out master (for the sake of it)</li>\n</ol>\n<p><em>It is based on <a href="https://stackoverflow.com/a/6300386/1998046">the answer</a> of <a href="https://stackoverflow.com/users/6309/vonc">VonC</a>.</em></p>\n'}, {'answer_id': 20783081, 'author': 'Sam', 'author_id': 1776255, 'author_profile': 'https://Stackoverflow.com/users/1776255', 'pm_score': 6, 'selected': False, 'text': "<p>This isn't too complicated. Very simple and straightforward steps are as follows;</p>\n<p><code>git fetch origin</code>: This will bring all the remote branches to your local.</p>\n<p><code>git branch -a</code>: This will show you all the remote branches.</p>\n<p><code>git checkout --track origin/&lt;branch you want to checkout&gt;</code></p>\n<p>Verify whether you are in the desired branch by the following command;</p>\n<pre><code>git branch\n</code></pre>\n<p>The output will like this;</p>\n<pre><code>*your current branch\nsome branch2\nsome branch3\n</code></pre>\n<p>Notice the * sign that denotes the current branch.</p>\n"}, {'answer_id': 22199624, 'author': 'Cerran', 'author_id': 3198108, 'author_profile': 'https://Stackoverflow.com/users/3198108', 'pm_score': 6, 'selected': False, 'text': '<h2>Why you only see "master"</h2>\n\n<p><code>git clone</code> downloads all remote branches but still considers them "remote", even though the files are located in your new repository. There\'s one exception to this, which is that the cloning process creates a local branch called "master" from the remote branch called "master". By default, <code>git branch</code> only shows local branches, which is why you only see "master".</p>\n\n<p><code>git branch -a</code> shows all branches, <em>including remote branches</em>.</p>\n\n<hr>\n\n<h2>How to get local branches</h2>\n\n<p>If you actually want to work on a branch, you\'ll probably want a "local" version of it. To simply create local branches from remote branches <em>(without checking them out and thereby changing the contents of your working directory)</em>, you can do that like this:</p>\n\n<pre><code>git branch branchone origin/branchone\ngit branch branchtwo origin/branchtwo\ngit branch branchthree origin/branchthree\n</code></pre>\n\n<p>In this example, <code>branchone</code> is the name of a local branch you\'re creating based on <code>origin/branchone</code>; if you instead want to create local branches with different names, you can do this:</p>\n\n<pre><code>git branch localbranchname origin/branchone\n</code></pre>\n\n<p>Once you\'ve created a local branch, you can see it with <code>git branch</code> (remember, you don\'t need <code>-a</code> to see local branches).</p>\n'}, {'answer_id': 27020944, 'author': 'Haimei', 'author_id': 2730862, 'author_profile': 'https://Stackoverflow.com/users/2730862', 'pm_score': 5, 'selected': False, 'text': "<p>You only need to use &quot;git clone&quot; to get all branches.</p>\n<pre><code>git clone &lt;your_http_url&gt;\n</code></pre>\n<p>Even though you only see the master branch, you can use &quot;git branch -a&quot; to see all branches.</p>\n<pre><code>git branch -a\n</code></pre>\n<p>And you can switch to any branch which you already have.</p>\n<pre><code>git checkout &lt;your_branch_name&gt;\n</code></pre>\n<p>Don't worry that after you &quot;git clone&quot;, you don't need to connect with the remote repository. &quot;git branch -a&quot; and &quot;git checkout &lt;your_branch_name&gt;&quot; can be run successfully when you don't have an Internet connection. So it is proved that when you do &quot;git clone&quot;, it already has copied all branches from the remote repository. After that, you don't need the remote repository. Your local already has all branches' code.</p>\n"}, {'answer_id': 28115781, 'author': 'Gaui', 'author_id': 1053611, 'author_profile': 'https://Stackoverflow.com/users/1053611', 'pm_score': 4, 'selected': False, 'text': '<p>None of these answers cut it, except <a href="https://stackoverflow.com/questions/67699/how-to-clone-all-remote-branches-in-git/16563327#16563327">user nobody is on the right track</a>.</p>\n<p>I was having trouble with moving a repository from one server/system to another. When I cloned the repository, it only created a local branch for master, so when I pushed to the new remote, only the master branch was pushed.</p>\n<p>So I found these two methods <em>very</em> useful.</p>\n<p><strong>Method 1:</strong></p>\n<pre><code>git clone --mirror OLD_REPO_URL\ncd new-cloned-project\nmkdir .git\nmv * .git\ngit config --local --bool core.bare false\ngit reset --hard HEAD\ngit remote add newrepo NEW_REPO_URL\ngit push --all newrepo\ngit push --tags newrepo\n</code></pre>\n<p><strong>Method 2:</strong></p>\n<pre><code>git config --global alias.clone-branches \'! git branch -a | sed -n &quot;/\\/HEAD /d; /\\/master$/d; /remotes/p;&quot; | xargs -L1 git checkout -t\'\ngit clone OLD_REPO_URL\ncd new-cloned-project\ngit clone-branches\ngit remote add newrepo NEW_REPO_URL\ngit push --all newrepo\ngit push --tags newrepo\n</code></pre>\n'}, {'answer_id': 28617347, 'author': 'Tebe', 'author_id': 758158, 'author_profile': 'https://Stackoverflow.com/users/758158', 'pm_score': 4, 'selected': False, 'text': "<p>Looking at one of the answers to the question I noticed that it's possible to shorten it:</p>\n<pre><code>for branch in  `git branch -r | grep -v 'HEAD\\|master'`; do\n    git branch --track ${branch##*/} $branch;\ndone\n</code></pre>\n<p>But beware, if one of remote branches is named, e.g., <em>admin_master</em> it won't get downloaded!</p>\n"}, {'answer_id': 32501388, 'author': 'jofel', 'author_id': 1182783, 'author_profile': 'https://Stackoverflow.com/users/1182783', 'pm_score': 3, 'selected': False, 'text': "<p>Here is another short one-liner command which\ncreates local branches for all remote branches:</p>\n\n<pre><code>(git branch -r | sed -n '/-&gt;/!s#^  origin/##p' &amp;&amp; echo master) | xargs -L1 git checkout\n</code></pre>\n\n<p>It works also properly if tracking local branches are already created.\nYou can call it after the first <code>git clone</code> or any time later.</p>\n\n<p>If you do not need to have <code>master</code> branch checked out after cloning, use </p>\n\n<pre><code>git branch -r | sed -n '/-&gt;/!s#^  origin/##p'| xargs -L1 git checkout\n</code></pre>\n"}, {'answer_id': 34122093, 'author': 'FedericoCapaldo', 'author_id': 3245486, 'author_profile': 'https://Stackoverflow.com/users/3245486', 'pm_score': 5, 'selected': False, 'text': "<p>All the answers I saw here were valid, but there is a much cleaner way to clone a repository and to pull all the branches at once.</p>\n<p>When you clone a repository, all the information of the branches is actually downloaded, but the branches are hidden. With the command</p>\n<pre><code>git branch -a\n</code></pre>\n<p>you can show all the branches of the repository, and with the command</p>\n<pre><code>git checkout -b branchname origin/branchname\n</code></pre>\n<p>you can then &quot;download&quot; them manually one at a time.</p>\n<hr />\n<p>However, when you want to clone a repository with a lot of branches, all the ways illustrated in previous answers are lengthy and tedious in respect to a much cleaner and quicker way that I am going to show, though it's a bit complicated. You need three steps to accomplish this:</p>\n<h3>1. First step</h3>\n<p>Create a new empty folder on your machine and clone a mirror copy of the <em>.git</em> folder from the repository:</p>\n<pre><code>cd ~/Desktop &amp;&amp; mkdir my_repo_folder &amp;&amp; cd my_repo_folder\ngit clone --mirror https://github.com/planetoftheweb/responsivebootstrap.git .git\n</code></pre>\n<p>The local repository inside the folder my_repo_folder is still empty, and there is just a hidden <em>.git</em> folder now that you can see with a &quot;ls -alt&quot; command from the terminal.</p>\n<h3>2. Second step</h3>\n<p>Switch this repository from an empty (bare) repository to a regular repository by switching the boolean value &quot;bare&quot; of the Git configurations to false:</p>\n<pre><code>git config --bool core.bare false\n</code></pre>\n<h3>3. Third Step</h3>\n<p>Grab everything that inside the current folder and create all the branches on the local machine, therefore making this a normal repository.</p>\n<pre><code>git reset --hard\n</code></pre>\n<p>So now you can just type the command &quot;git branch&quot; and you can see that all the branches are downloaded.</p>\n<p>This is the quick way in which you can clone a Git repository with all the branches at once, but it's not something you want to do for every single project in this way.</p>\n"}, {'answer_id': 35948878, 'author': 'Phil', 'author_id': 3432865, 'author_profile': 'https://Stackoverflow.com/users/3432865', 'pm_score': 3, 'selected': False, 'text': '<h1>Use commands that you can remember</h1>\n<p>I\'m using Bitbucket, a repository hosting service of Atlassian. So I try to follow their documentation. And that works perfectly for me. With the following easy and short commands you can checkout your remote branch.</p>\n<p>At first clone your repository, and then change into the destination folder. And last, but not least, fetch and checkout:</p>\n<pre><code>git clone &lt;repo&gt; &lt;destination_folder&gt;\ncd &lt;destination_folder&gt;\ngit fetch &amp;&amp; git checkout &lt;branch&gt;\n</code></pre>\n<p>That\'s it. Here a little more real-world example:</p>\n<pre><code>git clone https://username@bitbucket.org/team/repository.git project_folder\ncd project_folder\ngit fetch &amp;&amp; git checkout develop\n</code></pre>\n<p>You will find detail information about the commands in the documentation:\n<a href="https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-clone" rel="nofollow noreferrer">Clone Command</a>, <a href="https://www.atlassian.com/git/tutorials/syncing/git-fetch" rel="nofollow noreferrer">Fetch Command</a>, <a href="https://www.atlassian.com/git/tutorials/undoing-changes/git-checkout/" rel="nofollow noreferrer">Checkout Command</a></p>\n'}, {'answer_id': 36322324, 'author': 'kenorb', 'author_id': 55075, 'author_profile': 'https://Stackoverflow.com/users/55075', 'pm_score': 3, 'selected': False, 'text': '<p>Git usually (when not specified) fetches all branches and/or tags (refs, see: <code>git ls-refs</code>) from one or more other repositories along with the objects necessary to complete their histories. In other words, it fetches the objects which are reachable by the objects that are already downloaded. See: <a href="https://stackoverflow.com/a/36243207/55075">What does <code>git fetch</code> really do?</a></p>\n<p>Sometimes you may have branches/tags which aren\'t directly connected to the current one, so <code>git pull --all</code>/<code>git fetch --all</code> won\'t help in that case, but you can list them by:</p>\n<pre><code>git ls-remote -h -t origin\n</code></pre>\n<p>And fetch them manually by knowing the ref names.</p>\n<p>So to <strong>fetch them all</strong>, try:</p>\n<pre><code>git fetch origin --depth=10000 $(git ls-remote -h -t origin)\n</code></pre>\n<p><sup>The <code>--depth=10000</code> parameter may help if you\'ve shallowed repository.</sup></p>\n<p>Then check all your branches again:</p>\n<pre><code>git branch -avv\n</code></pre>\n<hr />\n<p>If the above won\'t help, you need to add missing branches manually to the tracked list (as they got lost somehow):</p>\n<pre><code>$ git remote -v show origin\n\n...\n  Remote branches:\n    master      tracked\n</code></pre>\n<p>by <code>git remote set-branches</code> like:</p>\n<pre><code>git remote set-branches --add origin missing_branch\n</code></pre>\n<p>so it may appear under <code>remotes/origin</code> after fetch:</p>\n<pre><code>$ git remote -v show origin\n\n...\n  Remote branches:\n    missing_branch new (next fetch will store in remotes/origin)\n$ git fetch\nFrom github.com:Foo/Bar\n * [new branch]      missing_branch -&gt; origin/missing_branch\n</code></pre>\n<hr />\n<h3>Troubleshooting</h3>\n<p>If you still cannot get anything other than the master branch, check the following:</p>\n<ul>\n<li>Double check your remotes (<code>git remote -v</code>), e.g.\n<ul>\n<li>Validate that <code>git config branch.master.remote</code> is <code>origin</code>.</li>\n<li>Check if <code>origin</code> points to the right URL via: <code>git remote show origin</code> (see <a href="https://stackoverflow.com/q/5243231/55075">this post</a>).</li>\n</ul>\n</li>\n</ul>\n'}, {'answer_id': 37906446, 'author': 'gringo_dave', 'author_id': 545918, 'author_profile': 'https://Stackoverflow.com/users/545918', 'pm_score': 4, 'selected': False, 'text': '<p>I wrote these small <strong>PowerShell</strong> functions to be able to checkout all my Git branches, that are on origin remote.</p>\n<pre><code>Function git-GetAllRemoteBranches {\n     iex &quot;git branch -r&quot;                       &lt;# get all remote branches #&gt; `\n     | % { $_ -Match &quot;origin\\/(?\'name\'\\S+)&quot; }  &lt;# select only names of the branches #&gt; `\n     | % { Out-Null; $matches[\'name\'] }        &lt;# write does names #&gt;\n}\n\n\nFunction git-CheckoutAllBranches {\n    git-GetAllRemoteBranches `\n        | % { iex &quot;git checkout $_&quot; }          &lt;# execute \' git checkout &lt;branch&gt;\' #&gt;\n}\n</code></pre>\n<p>More Git functions can be found in <a href="https://github.com/aburok/mysettings/blob/master/PowerShell/config/git-alias.ps1" rel="nofollow noreferrer">my Git settings repository</a>.</p>\n'}, {'answer_id': 41082358, 'author': 'Albert.Qing', 'author_id': 770627, 'author_profile': 'https://Stackoverflow.com/users/770627', 'pm_score': 4, 'selected': False, 'text': '<pre><code>#!/bin/bash\nfor branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do\n   git branch --track ${branch#remotes/origin/} $branch\ndone\n</code></pre>\n<p>These code will pull all remote branches code to the local repository.</p>\n'}, {'answer_id': 42428398, 'author': 'raisercostin', 'author_id': 99248, 'author_profile': 'https://Stackoverflow.com/users/99248', 'pm_score': 4, 'selected': False, 'text': '<p>Cloning from a local repo will not work with git clone &amp; git fetch: a lot of branches/tags will remain unfetched.</p>\n\n<p>To get a clone with all branches and tags.</p>\n\n<pre><code>git clone --mirror git://example.com/myproject myproject-local-bare-repo.git\n</code></pre>\n\n<p>To get a clone with all branches and tags but also with a working copy:</p>\n\n<pre><code>git clone --mirror git://example.com/myproject myproject/.git\ncd myproject\ngit config --unset core.bare\ngit config receive.denyCurrentBranch updateInstead\ngit checkout master\n</code></pre>\n'}, {'answer_id': 43551285, 'author': 'ashes999', 'author_id': 210780, 'author_profile': 'https://Stackoverflow.com/users/210780', 'pm_score': 3, 'selected': False, 'text': '<p>As of early 2017, the answer <a href="https://stackoverflow.com/questions/67699/how-to-clone-all-remote-branches-in-git#comment2170694_72156">in this comment</a> works:</p>\n\n<p><code>git fetch &lt;origin-name&gt; &lt;branch-name&gt;</code> brings the branch down for you. While this doesn\'t pull all branches at once, you can singularly execute this per-branch.</p>\n'}, {'answer_id': 45257871, 'author': 'Alireza', 'author_id': 5423108, 'author_profile': 'https://Stackoverflow.com/users/5423108', 'pm_score': 4, 'selected': False, 'text': '<p><strong>OK,</strong> when you clone your repo, you have all branches there...</p>\n\n<p>If you just do <code>git branch</code>, they are kind of hidden...</p>\n\n<p>So if you\'d like to see all branches name, just simply add <code>--all</code> flag like this:</p>\n\n<p><code>git branch --all</code> or <code>git branch -a</code></p>\n\n<p>If you just checkout to the branch, you get all you need.</p>\n\n<p>But how about if the branch created by someone else after you clone?</p>\n\n<p>In this case, just do:</p>\n\n<p><code>git fetch</code></p>\n\n<p>and check all branches again...</p>\n\n<p>If you like to fetch and checkout at the same time, you can do:</p>\n\n<p><code>git fetch &amp;&amp; git checkout your_branch_name</code></p>\n\n<p>Also created the image below for you to simplify what I said:</p>\n\n<p><a href="https://i.stack.imgur.com/gn2pi.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gn2pi.png" alt="git branch --all to get all branches"></a></p>\n'}, {'answer_id': 50534323, 'author': 'Bernd Jungblut', 'author_id': 1106617, 'author_profile': 'https://Stackoverflow.com/users/1106617', 'pm_score': 4, 'selected': False, 'text': '<p><code>git clone --mirror</code> on the original repo works well for this.</p>\n\n<pre><code>git clone --mirror /path/to/original.git\ngit remote set-url origin /path/to/new-repo.git\ngit push -u origin\n</code></pre>\n'}, {'answer_id': 51909504, 'author': 'M. Dhaouadi', 'author_id': 6928576, 'author_profile': 'https://Stackoverflow.com/users/6928576', 'pm_score': -1, 'selected': False, 'text': '<p>If you use Bitbucket, you can use <strong>import Repository</strong>. This will import all Git history (all the branches and commits).</p>\n'}, {'answer_id': 53684037, 'author': 'lacostenycoder', 'author_id': 3625433, 'author_profile': 'https://Stackoverflow.com/users/3625433', 'pm_score': 2, 'selected': False, 'text': '<p>This variation will clone a remote repo with all branches available locally without having to checkout each branch one by one. No fancy scripts needed.</p>\n\n<p>Make a folder with the same name of the repo you wish to clone and cd into for example:</p>\n\n<pre><code>mkdir somerepo\ncd somerepo\n</code></pre>\n\n<p>Now do these commands but with actual repo usersname/reponame </p>\n\n<pre><code>git clone --bare git@github.com:someuser/somerepo.git .git\ngit config --bool core.bare false\ngit reset --hard\ngit branch\n</code></pre>\n\n<p>Voiala! you have all the branches there!</p>\n'}, {'answer_id': 56687773, 'author': 'konsolebox', 'author_id': 445221, 'author_profile': 'https://Stackoverflow.com/users/445221', 'pm_score': 3, 'selected': False, 'text': '<p>Here\'s an answer that uses awk.  This method should suffice if used on a new repo.</p>\n\n<pre><code>git branch -r | awk -F/ \'{ system("git checkout " $NF) }\'\n</code></pre>\n\n<p>Existing branches will simply be checked out, or declared as already in it, but filters can be added to avoid the conflicts.</p>\n\n<p>It can also be modified so it calls an explicit <code>git checkout -b &lt;branch&gt; -t &lt;remote&gt;/&lt;branch&gt;</code> command.</p>\n\n<p>This answer follows <a href="https://stackoverflow.com/users/856199/nikos-c">Nikos C.</a>\'s <a href="https://stackoverflow.com/a/10563611/445221">idea</a>.</p>\n\n<hr>\n\n<p>Alternatively we can specify the remote branch instead.  This is based on <a href="https://stackoverflow.com/users/144330/murphytalk">murphytalk</a>\'s <a href="https://stackoverflow.com/a/1186645/445221">answer</a>.</p>\n\n<pre><code>git branch -r | awk \'{ system("git checkout -t " $NF) }\'\n</code></pre>\n\n<p>It throws fatal error messages on conflicts but I see them harmless.</p>\n\n<hr>\n\n<p>Both commands can be aliased.</p>\n\n<p>Using <a href="https://stackoverflow.com/users/2383918/nobody">nobody</a>\'s <a href="https://stackoverflow.com/a/16563327/445221">answer</a> as reference, we can have the following commands to create the aliases:</p>\n\n<pre><code>git config --global alias.clone-branches \'! git branch -r | awk -F/ "{ system(\\"git checkout \\" \\$NF) }"\'\ngit config --global alias.clone-branches \'! git branch -r | awk "{ system(\\"git checkout -t \\" \\$NF) }"\'\n</code></pre>\n\n<p>Personally I\'d use <code>track-all</code> or <code>track-all-branches</code>.</p>\n'}, {'answer_id': 58101436, 'author': 'Tony Barganski', 'author_id': 2305748, 'author_profile': 'https://Stackoverflow.com/users/2305748', 'pm_score': 4, 'selected': False, 'text': '<h3>Self-Contained Repository</h3>\n<p>If you’re looking for a <em><strong>self-contained clone or backup</strong></em> that <em>includes</em> all remote branches and commit logs, use:</p>\n<pre><code>git clone http://user@repo.url\n</code></pre>\n<pre><code>git pull --all\n</code></pre>\n<p>The accepted answer of <code>git branch -a</code> only <em><strong>shows</strong></em> the remote branches. If you attempt to <code>checkout</code> the branches you\'ll be unable to  unless you still have <em><strong>network access</strong></em> to the origin server.</p>\n<p><strong>Credit:</strong>  <a href="https://stackoverflow.com/a/4682612/2305748">Gabe Kopley\'s</a> for suggesting using <code>git pull --all</code>.</p>\n<p><strong>Note:</strong><br />\nOf course, if you no longer have network access to the <strong><code>remote/origin</code></strong> server, <strong><code>remote/origin branches</code></strong> will not have any updates reflected in your repository clone. Their revisions will reflect commits from the date and time you performed the two repository cloning commands above.</p>\n<br />\nCheckout a *local* branch in the usual way with `git checkout remote/origin/` Use `git branch -a` to reveal the remote branches saved within your `clone` repository.\n<p>To checkout ALL your <em>clone</em> branches to <em>local branches</em> with one command, use one of the bash commands below:</p>\n<pre class="lang-sh prettyprint-override"><code>$ for i in $(git branch -a |grep \'remotes\' | awk -F/ \'{print $3}\' \\ \n| grep -v \'HEAD -&gt;\');do git checkout -b $i --track origin/$i; done\n</code></pre>\n<p>OR</p>\n<p>If your repo has nested branches then this command will take that into account also:</p>\n<pre class="lang-sh prettyprint-override"><code>for i in $(git branch -a |grep \'remotes\' |grep -v \'HEAD -&gt;\');do \\\nbasename ${i##\\./} | xargs -I {} git checkout -b {} --track origin/{}; done\n</code></pre>\n<br />\n<p>The above commands will <code>checkout</code> a local branch into your local git repository, named the same as the <em><code>remote/origin/&lt;branchname&gt;</code></em> and set it to <code>--track</code> changes from the remote branch on the <em><code>remote/origin</code></em> server should you regain network access to your origin repo server once more and perform a <code>git pull</code> command in the usual way.</p>\n'}, {'answer_id': 58218112, 'author': 'Marcelo Viana', 'author_id': 3880899, 'author_profile': 'https://Stackoverflow.com/users/3880899', 'pm_score': -1, 'selected': False, 'text': '<h1>allBranches</h1>\n\n<p>Script to download all braches from a Git project</p>\n\n<h2>Installation:</h2>\n\n<pre><code>sudo git clone https://github.com/marceloviana/allBranches.git &amp;&amp; sudo cp -rfv allBranches/allBranches.sh /usr/bin/allBranches &amp;&amp; sudo chmod +x /usr/bin/allBranches &amp;&amp; sudo rm -rf allBranches\n</code></pre>\n\n<p>Ready! Now just call the command (allBranches) and tell the Git project directory that you want to download all branches</p>\n\n<p><strong>Use</strong></p>\n\n<p>Example 1:</p>\n\n<pre><code>~$ allBranches /var/www/myproject1/\n</code></pre>\n\n<p>Example 2:</p>\n\n<pre><code>~$ allBranches /var/www/myproject2/\n</code></pre>\n\n<p>Example 3 (if already inside the project directory):</p>\n\n<pre><code>~$ allBranches ./\n</code></pre>\n\n<p>or</p>\n\n<pre><code>~$ allBranches .\n</code></pre>\n\n<p>View result:</p>\n\n<pre><code>git branch\n</code></pre>\n\n<h3>Reference:</h3>\n\n<p>Repository allBranches GitHub:\n<a href="https://github.com/marceloviana/allBranches" rel="nofollow noreferrer">https://github.com/marceloviana/allBranches</a></p>\n'}, {'answer_id': 59863601, 'author': 'ioedeveloper', 'author_id': 8225842, 'author_profile': 'https://Stackoverflow.com/users/8225842', 'pm_score': 0, 'selected': False, 'text': '<p>A better alternative solution for developers using <a href="https://en.wikipedia.org/wiki/Visual_Studio_Code" rel="nofollow noreferrer">Visual Studio Code</a> is to use <a href="https://marketplace.visualstudio.com/items?itemName=ioedeveloper.git-shadow" rel="nofollow noreferrer">Git Shadow Extension</a>.</p>\n<p>This Visual Studio Code extension allows cloning repository content and directories, that can be filtered by branch name or commit hash. That way, branches or commits can be used as boilerplates/templates for new projects.</p>\n'}, {'answer_id': 62977519, 'author': 'Vopel', 'author_id': 11777065, 'author_profile': 'https://Stackoverflow.com/users/11777065', 'pm_score': 0, 'selected': False, 'text': '<p>Here\'s a cross-platform <strong>PowerShell 7</strong> function adapted from the previous answers.</p>\n<pre class="lang-none prettyprint-override"><code>function Invoke-GitCloneAll($url) {\n    $repo = $url.Split(\'/\')[-1].Replace(\'.git\', \'\')\n    $repo_d = Join-Path $pwd $repo\n    if (Test-Path $repo_d) {\n        Write-Error &quot;fatal: destination path \'$repo_d\' already exists and is not an empty directory.&quot; -ErrorAction Continue\n    } else {\n        Write-Host &quot;`nCloning all branches of $repo...&quot;\n        git -c fetch.prune=false clone $url -q --progress &amp;&amp;\n        git -c fetch.prune=false --git-dir=&quot;$(Join-Path $repo_d \'.git\')&quot; --work-tree=&quot;$repo_d&quot; pull --all\n        Write-Host &quot;&quot; #newline\n    }\n}\n</code></pre>\n<p><strong>Note:</strong> <code>-c fetch.prune=false</code> makes it include stale branches that would normally be excluded. Remove that if you\'re not interested in it.</p>\n<hr />\n<p><em>You can make this work with PowerShell 5.1 (the default in Windows 10) by removing <code>&amp;&amp;</code> from the function, but that makes it try to <code>git pull</code> even when the previous command failed. So, I strongly recommend just using the cross-platform PowerShell it\'s always bugging you about trying.</em></p>\n'}, {'answer_id': 63061894, 'author': 'jasonleonhard', 'author_id': 1783588, 'author_profile': 'https://Stackoverflow.com/users/1783588', 'pm_score': 1, 'selected': False, 'text': '<h3>Here, I wrote you a nice function to make it easily repeatable</h3>\n<pre class="lang-sh prettyprint-override"><code>gitCloneAllBranches() { # clone all git branches at once easily and cd in\n  # clone as &quot;bare repo&quot;\n  git clone --mirror $1\n  # rename without .git extension\n  with_extension=$(basename $1)\n  without_extension=$(echo $with_extension | sed \'s/.git//\')\n  mv $with_extension $without_extension\n  cd $without_extension\n  # change from &quot;bare repository&quot; to not\n  git config --bool core.bare false\n  # check if still bare repository if so\n  if [[ $(git rev-parse --is-bare-repository) == false ]]; then\n    echo &quot;ready to go&quot;\n  else\n    echo &quot;WARNING: STILL BARE GIT REPOSITORY&quot;\n  fi\n  # EXAMPLES:\n  # gitCloneAllBranches https://github.com/something/something.git\n}\n</code></pre>\n'}, {'answer_id': 63134844, 'author': 'Astor', 'author_id': 9326701, 'author_profile': 'https://Stackoverflow.com/users/9326701', 'pm_score': 2, 'selected': False, 'text': '<p>This solution worked for me to &quot;copy&quot; a repository to another one:</p>\n<pre><code>git merge path/to/source.git --mirror\ncd source.git\ngit remote remove origin\ngit remote add origin path/to/target.git\ngit push origin --all\ngit push origin --tags\n</code></pre>\n<p>On target repository I can see the same branches and tags than the origin repo.</p>\n'}, {'answer_id': 63970897, 'author': 'STREET MONEY', 'author_id': 9082515, 'author_profile': 'https://Stackoverflow.com/users/9082515', 'pm_score': 1, 'selected': False, 'text': '<p>This is what I do whenever I need to bring down all branches. Credits to <strong>Ray Villalobos</strong> from Linkedin Learning. Try cloning all branches including commits:</p>\n<pre><code>mkdir -p -- newproject_folder\ncd newproject_folder\ngit clone --mirror https://github.com/USER_NAME/RepositoryName.git .git\ngit config --bool core.bare false\ngit reset --hard\n</code></pre>\n'}, {'answer_id': 68359412, 'author': 'Victor Mwenda', 'author_id': 3131579, 'author_profile': 'https://Stackoverflow.com/users/3131579', 'pm_score': 0, 'selected': False, 'text': '<p>Do a bare clone of the remote repository, save the contents to a .git directory</p>\n<pre><code>git clone --bare remote-repo-url.git localdirname/.git\n</code></pre>\n<p>(A bare git repository, created using git clone --bare or git init --bare, is a storage repository, it does not have a working directory, you cannot create or modify files there.)</p>\n<p>Change directory to your local directory</p>\n<pre><code>cd localdirname\n</code></pre>\n<p>Make your git repository modifiable</p>\n<pre><code>git config --bool core.bare false\n</code></pre>\n<p>Restore your working directory</p>\n<pre><code>git reset --hard\n</code></pre>\n<p>List all your branches</p>\n<pre><code>git branch -al\n</code></pre>\n'}, {'answer_id': 68582362, 'author': 'Devin Rhode', 'author_id': 565877, 'author_profile': 'https://Stackoverflow.com/users/565877', 'pm_score': 3, 'selected': False, 'text': '<p>To create a &quot;full&quot; backup of all branches+refs+tags+etc stored in your git host (github/bitbucket/etc), run:</p>\n<pre class="lang-bash prettyprint-override"><code>mkdir -p -- myapp-mirror\ncd myapp-mirror\ngit clone --mirror https://git.myco.com/group/myapp.git .git\ngit config --bool core.bare false\ngit config --bool core.logAllRefUpdates true\ngit reset --hard # restore working directory\n</code></pre>\n<p>This is compiled from everything I\'ve learned from other answers.</p>\n<p>You can then use this local repo mirror to transition to a different SCM system/git host, or you can keep this as a backup. It\'s also useful as a search tool, since most git hosts only search code on the &quot;main&quot; branch of each repo, if you <code>git log -S&quot;specialVar&quot;</code>, you\'ll see all code on all branches.</p>\n<p>Note: if you want to use this repo in your day-to-day work, run:</p>\n<pre class="lang-bash prettyprint-override"><code>git config --unset remote.origin.mirror\n</code></pre>\n<p>WARNING: you may run into strange issues if you attempt to use this in your day-to-day work. If your ide/editor is doing some auto-fetching, your local <code>master</code> may update because, you did <code>git clone --mirror</code>. Then those files appear in your git staging area. I actually had a situation where I\'m on a local feature branch.. that branch has no commits, and all files in the repo appear in the staging area. Just nuts.</p>\n'}, {'answer_id': 69055255, 'author': 'Ricardo', 'author_id': 2571805, 'author_profile': 'https://Stackoverflow.com/users/2571805', 'pm_score': 3, 'selected': False, 'text': '<p>I\'m cloning a repository from the Udemy course <a href="https://www.udemy.com/course/elegant-automation-frameworks-with-python-and-pytest/" rel="nofollow noreferrer">Elegant Automation Frameworks with Python and Pytest</a>, so that I can later go over it <strong>OFFLINE</strong>. I tried downloading the zip, but this only comes for the current branch, so here are my 2 cents.</p>\n<p>I\'m working on Windows and, obviously, I resorted to the Ubuntu shell from the <a href="https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux" rel="nofollow noreferrer">Windows Subsystem for Linux</a>. Immediately after cloning, here\'s my branches:</p>\n<pre class="lang-none prettyprint-override"><code>$ git clone https://github.com/BrandonBlair/elegantframeworks.git\n\n$ git branch -a\n\n* master\n  remotes/origin/HEAD -&gt; origin/master\n  remotes/origin/config_recipe\n  remotes/origin/functionaltests\n  remotes/origin/master\n  remotes/origin/parallel\n  remotes/origin/parametrize\n  remotes/origin/parametrize_data_excel\n  remotes/origin/unittesting\n  remotes/origin/unittesting1\n</code></pre>\n<p>Then — and after hitting a few <code>git checkout</code> brick walls —, what finally worked for me was:</p>\n<pre class="lang-none prettyprint-override"><code>$ for b in `git branch -a | cut -c18- | cut -d\\  -f1`; do git checkout $b; git stash; done\n</code></pre>\n<p>After this, here are my branches:</p>\n<pre class="lang-none prettyprint-override"><code>$ git branch -a\n\n  config_recipe\n  functionaltests\n  master\n  parallel\n  parametrize\n  parametrize_data_excel\n  unittesting\n* unittesting1\n  remotes/origin/HEAD -&gt; origin/master\n  remotes/origin/config_recipe\n  remotes/origin/functionaltests\n  remotes/origin/master\n  remotes/origin/parallel\n  remotes/origin/parametrize\n  remotes/origin/parametrize_data_excel\n  remotes/origin/unittesting\n  remotes/origin/unittesting1\n</code></pre>\n<p>Mine goes physical, cutting out the initial <code>  remotes/origin/</code> and then filtering for space delimiters. Arguably, I could just have <code>grep</code>ed out <code>HEAD</code> and be done with one <code>cut</code>, but I\'ll leave that for the comments.</p>\n<p>Please notice that your current branch is now the last on the list. If you don\'t know why that is, you\'re in a tight spot there. Just <code>git checkout</code> whatever you want now.</p>\n'}, {'answer_id': 73141359, 'author': 'CervEd', 'author_id': 1507124, 'author_profile': 'https://Stackoverflow.com/users/1507124', 'pm_score': 1, 'selected': False, 'text': "<p>How to create a local branch for each branch on remote <code>origin</code> matching <code>pattern</code>.</p>\n<pre><code>#!/bin/sh\ngit fetch --all\ngit for-each-ref --format='%(refname:short)' refs/remotes/origin/pattern |\\\n    sed 's@\\(origin/\\)\\(.*\\)@\\2\\t\\1\\2@' |\\\n    xargs -n 2 git branch --track\n</code></pre>\n<p>All remote references (branches/tags) are fetched and then local references are created. Should work on most systems, fast, without checking out the index or relying on bashisms.</p>\n"}]
['https://Stackoverflow.com/questions/67699', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/117/']