Question

I'm often building servers where the goal is to install some software that is stored in Github. The process goes:

  1. Install Git.
  2. Clone the Github repo.
  3. Checkout the right branch.

Steps 1 and 2 can be pretty slow (a few minutes). Are there any tools that would allow me to cut to the chase, step 3? I'm thinking something like:

  1. Get gitcheckout tool (bash script)
  2. It directly pulls down the relevant files from the right branch in Github.
Était-ce utile?

La solution

If you want to use git and if your git is new enough to have --single-branch:

git clone --single-branch --branch=<branch> --depth=1

Otherwise, you can download the source in a zip:

wget https://github.com/<user>/<project>/archive/<branch>.zip

Autres conseils

curl or wget:

curl -o foo.zip https://github.com/<user>/<project>/archive/<branch>.zip
wget https://github.com/<user>/<project>/archive/<branch>.zip

that said, in my experience, installing git only takes a few seconds

  1. You could get a tarball using the GitHub API, and then you could get a branch and extract it in one go:

    curl -u USER:TOKEN https://api.github.com/repos/USER/REPO/tarball/BRANCH -L | tar zt
    

    You can create your token following the steps on this page. It's easy enough to do.

  2. Or you could get a sub-directory using svn:

    svn checkout https://github.com/USER/REPO/branches/BRANCH/subdir/you/want
    

The good thing about both solutions is that they don't download the full history, only the snapshot of the latest state.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top