Git does not support cloning of individual files or directories but if the remote repository (for example GitHub, GitLab, or Bitbucket) is public, you can use wget or curl command to get a single file from your remote repository.
Example:
Copy a single file from a public remote repository (GitHub):
1 2 3 |
## Copy the README.md file of git source code hosted in GitHub ## wget https://github.com/username/reponame/branch/path/to/file wget https://github.com/git/git/blob/master/README.md |
Get the content of a single file from public remote repository (GitHub):
1 2 3 |
## Display the content of README.md file of git source code hosted in GitHub ## curl https://raw.githubusercontent.com/username/reponame/branch/path/to/file curl https://raw.githubusercontent.com/git/git/master/README.md |
Copy a single file from a public remote repository (GitLab):
1 2 3 |
## Copy the README.md file of gitlab source code hosted in GitLab ## wget https://gitlab.com/username/reponame/-/blob/branch/path/to/file wget https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md |
Get the content of a single file from public remote repository (GitLab):
1 2 3 |
## Display the content of README.md file of gitlab source code hosted in GitLab ## curl https://gitlab.com/username/reponame/-/raw/branch/path/to/file curl https://gitlab.com/gitlab-org/gitlab/-/raw/master/README.md |
Copy a single file from a public remote repository ( Bitbucket ):
1 2 3 |
## Copy the README.md file of a source code hosted in Bitbucket ## wget https://bitbucket.org/username/reponame/src/branch/path/to/file wget https://bitbucket.org/atlassian/bitbucket-upload-file/src/master/README.md |
Get the content of a single file from public remote repository (Bitbucket):
1 2 3 |
## Display the content of README.md file of a source code hosted in Bitbucket ## curl https://bitbucket.org/username/reponame/raw/commit_sha/path/to/file curl https://bitbucket.org/atlassian/bitbucket-upload-file/raw/b2d97abff8c32435f5ea3dd40146e272d20ad1a7/README.md |