Introduction
I have a local repository with a remote branch called gh-pages
:
$ git branch -v -a * master edfa5f3 Adds README for JSDoc. remotes/origin/HEAD -> origin/master remotes/origin/gh-pages f7ab217 Switch to JSDoc 3.4.0-dev (Sun, 14 Jun 2015 18:49:07 GMT) remotes/origin/master edfa5f3 Adds README for JSDoc.
And I can checkout a single branch from the remote origin into a single directory:
$ git clone `git ls-remote --get-url` --branch gh-pages --single-branch gh-pages
After that I have the gh-pages
branch in the gh-pages
directory. This works fine. The reason why I need to use two branches simultaneously is my source code documentation. The generation of the source code documentation takes the source code from the currently checked out branch and generates the HTML into the gh-pages
branch.
The disadvantage is, that I have to push the two branches independently to the remote origin.
Problem
Now I tried to get the same setup with just my local repository. But when I try to clone the gh-pages
branch from my local repository it fails:
$ git clone . --branch gh-pages --single-branch gh-pages Cloning into 'gh-pages'... warning: Could not find remote branch gh-pages to clone. fatal: Remote branch gh-pages not found in upstream origin fatal: The remote end hung up unexpectedly
After some reading I understood that the gh-pages
branch is missing in my local repository. So I tried to fetch it as explained here. But the fetch without checkout seems to do nothing:
$ git fetch $ git branch * master
I still do not have the gh-pages
branch. I do not want to check out the remote branch, I just want to have it to be able to clone it. How do I fetch the branch for clone instead of checkout?
After that I want to push from my gh-pages
clone into my local repository. And when I do a push from my local repository to the remote origin both branches, the master
and the gh-pages
branch, should be pushed.
Is this possible to do or do I have a misunderstanding about the way fetch
and push
actually work?