Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>By default <code>git clone</code> would fetch all branches, but those branches would be stored as remote-tracking branches: for example branch 'dev_XXXXX' would be stored as 'origin/dev_XXXXX' (with 'refs/remotes/origin/dev_XXXXX' as full name). Those remote-tracking branches wouldn't be visible in <code>git branch</code> output: you would need <code>git branch -r</code> to list remote-tracking branches (or <code>git branch -a</code> to list all branches). If those branches do not diverge too much from mainline, they wouldn't take too much disk space in repository. Therefore I don't see why you want to clone only selected branches.</p> <p>Nevertheless if you want to have a clone with only two selected branches, you can do it like this:</p> <ol> <li><p>First, create new empty repository</p> <pre><code>$ mkdir repoclone $ cd repoclone/ $ git init Initialized empty Git repository in /home/user/repoclone/.git/ </code></pre></li> <li><p>Then add your repository under the name 'origin' (just like "git clone" would name it), requesting tracking of only two branches: 'master' and 'dev_swamy', using "<a href="http://www.kernel.org/pub/software/scm/git/docs/git-remote.html" rel="noreferrer" title="git-remote(1) Manual Page - manage set of tracked repositories">git remote</a>" command. Check that it was added correctly.</p> <pre><code>$ git remote add -t master -t dev_swamy origin user@example.com:repo.git $ git remote origin $ git remote show origin * remote origin Fetch URL: user@example.com:repo.git Push URL: user@example.com:repo.git HEAD branch: master Remote branches: master new (next fetch will store in remotes/origin) dev_swamy new (next fetch will store in remotes/origin) </code></pre> <p>If the stable branch is called 'stable' rather than 'master', you would have of course to modify above example. Also there is <code>-m &lt;branch&gt;</code> option if you want specified branch to be default branch in remote.</p></li> <li><p>Fetch from 'origin' (you could do this also by using <code>-f</code> option to "git remote add" above):</p> <pre><code>$ git fetch remote: Counting objects: 282, done. remote: Compressing objects: 100% (193/193), done. remote: Total 282 (delta 82), reused 0 (delta 0) Receiving objects: 100% (282/282), 81.30 KiB | 135 KiB/s, done. Resolving deltas: 100% (82/82), done. From user@example.com:repo.git * [new branch] master -&gt; origin/master * [new branch] dev_swamy -&gt; origin/dev_swamy From user@example.com:repo.git * [new tag] v1.0 -&gt; v1.0 * [new tag] v1.0.1 -&gt; v1.0.1 * [new tag] v1.1 -&gt; v1.1 </code></pre></li> <li><p>Set up local branch 'master' (where you would do your work) to follow 'origin/master' (to have 'origin/master' as upstream), just like "git clone" would do:</p> <pre><code>$ git checkout -t origin/master Branch master set up to track remote branch master from origin. Already on 'master' </code></pre> <p>You can repeat this for branch 'dev_swamy'.</p></li> <li><p>Now you can see how config file looks like. <strong>You can get exactly the same result by editing <code>.git/config</code> file to look like the following, and then doing "git fetch"</strong>.</p> <pre><code>$ cat .git/config # or just open this file in your editor [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = user@example.com:repo.git fetch = +refs/heads/master:refs/remotes/origin/master fetch = +refs/heads/dev_swamy:refs/remotes/origin/dev_swamy [branch "master"] remote = origin merge = refs/heads/master </code></pre></li> </ol> <p>Don't forget to introduce yourself to Git before starting work on repository (i.e. set 'user.name' and 'user.email' config variables; usually in per-user config file)!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload