Depending on what you are trying to accomplish you have two options. If you want to be able to track changes to the files still, then I would commit symlinks. If you don't care about local changes, then I would use git archive
.
Commit symlinks
You can commit symlinks to the files that you care about, use spare checkout to get those as well.
ln -s contrib/completion/git-completion.bash git-completion.bash
git add git-completion.bash
This will allow you to edit the files and commit changes to them still.
Git archive
This will simply extract the content you are looking for. Changes will not be tracked in the repository.
# generic
git archive <revision>:<path> | tar -xf -
#specific to your example
git clone --bare https://github.com/git/git.git ~/git-completion-bare
mkdir git-completion && cd git-completion
git archive --remote ~/git-completion-bare master:contrib/completion/ | tar -xf -
Edit: It looks like github
does not support git archive --remote
. It is still included below in case someone is using a different hosting service that allows it.
Git archive with --remote
Using git archive, you can even download the changes directly from a remote repository without cloning the repository first. The downside is you cannot track local changes with Git.
# General form
git archive --remote <url> <revision>:<path> | tar -xf -
# your example
git archive --remote https://github.com/git/git.git master:contrib/completion/ | tar -xf -
You will now have the files in the current directory.