2

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.
2
  • 2
    Github offers branch downloads as a zip file. Is that what you're looking for? Commented Dec 9, 2013 at 23:37
  • 1
    You could use wget to pull down the zip of the whole repository, but you cannot download individual parts so with most projects you'd wind up downloading a lot of extra data (unneeded branches, etc) Commented Dec 9, 2013 at 23:41

3 Answers 3

4

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
Sign up to request clarification or add additional context in comments.

2 Comments

Perfect - I didn't know you could do either of those things. I seem to recall once looking for the equivalent of "--single-branch" and it definitely not existing then.
After experimenting with both a bit, wget is faster, but with the possible downside that you don't end up with a git repo at all - which other scripts etc may expect.
1

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

Comments

0
  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.

1 Comment

Very cool - two more (different) solutions. The SVN one is quite sneaky - but works because SVN is probably included in more distros than Git.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.