I need to clone a private repository from GitHub, but I only want to get a specific tag (so basically, cloning is actually the wrong term for it).
Now, the problem is that there are multiple options, and all of them don't really work out:
I think you can do this with
git clone --single-branch:
--[no-]single-branch Clone only the history leading to the tip of a single branch, either specified by the --branch option or the primary branch remote’s HEAD points at. When creating a shallow clone with the --depth option, this is the default, unless --no-single-branch is given to fetch the histories near the tips of all branches. Further fetches into the resulting repository will only update the remote-tracking branch for the branch this option was used for the initial cloning. If the HEAD at the remote did not point at any branch when --single-branch clone was made, no remote-tracking branch is created.
Note that this says you need a branch to be specified with
--branch, rather than a tag. However, the documentation for
--branch , -b Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository’s HEAD, point to branch instead. In a non-bare repository, this is the branch that will be checked out. --branch can also take tags and detaches the HEAD at that commit in the resulting repository.
The last sentence says you can use
--branch with a tag. The only thing I'm not sure of is whether you can both use
--single-branch and pass a tag to
--branch. I guess you will have to try that to confirm. Alternatively, you will have to create a branch in the remote repository as opposed to a tag.
You now say you also want to destroy the entire history. Do this afterwards.
git clean -xdf # Clean out everything not in git rm -rf .git # remove git git init . # put it back git add . # Add all the files git commit -a -m "Eternal sunshine of the spotless mind"
Living less dangerously
git rebase --root -i # needs recent version of git
then change every line to begin with
s to squash into the original commit.