George Edwards George Edwards - 1 month ago 7
Git Question

Changing name of top-level directory when downloading a tarball from GitHub?

I am trying to download the latest version of a specific github branch with curl.

curl -L https://github.com/nativescript/docs/tarball/production | tar zx


However, this creates a file such as
NativeScript-docs-ed0d16f
whihc is difficult to work with in code as the name will change for every commit. Is there a way to download that file, but for the folder to be called
docs-latest
from the command line?

Without knowing the name of the downloaded file?

Answer

Use the newer .../archive/... link rather than the .../tarball/... link in your question. The general format is:

https://github.com/<group_or_organization>/<repo>/archive/<refspec>.tar.gz

So, for example:

$ curl -L jttps://github.com/nativescript/docs/archive/production.tar.gz | tar tz
docs-production/
docs-production/.gitattributes
docs-production/.gitignore
docs-production/.gitmodules
docs-production/.vscode/
docs-production/.vscode/settings.json
docs-production/README.md
...

You can see that the generated top-level directory name uses whatever <refspec> you provided, rather than converting it into a commit id.

Similarly:

$ curl -s -L https://github.com/nativescript/docs/archive/ErikEdits-css-annimations.tar.gz   | tar tz
docs-ErikEdits-css-annimations/
docs-ErikEdits-css-annimations/.gitattributes
docs-ErikEdits-css-annimations/.gitignore
...

In place of a branch name you can use other git refspecs. For example:

https://github.com/nativescript/docs/archive/HEAD^.tar.gz

Or:

https://github.com/nativescript/docs/archive/v2.3.0-20-ged0d16f.tar.gz

But in these cases, the reference will be converted into a commit id.

Comments