I'm trying to retrieve a single file from by bitbucket branch instead of getting the entire branch using the git module. It's taking more than 2 minutes to get the entire branch and I really just need that one file.
Asked
Active
Viewed 3,579 times
3 Answers
0
You can try git archive to get a file from remote git repository
git archive --remote=git://git.example.com/project.git HEAD:path/in/repo filename | tar -x
You can refer to the answer by Vonc for detailed information - For more info
Rajan Sharma
- 1,956
- 3
- 18
- 32
0
You can use sparse checkout option
git config core.sparseCheckout true
git remote add -f origin git:<<providde url>
echo "path/to/folder/*" > .git/info/sparse-checkout
git checkout <branchname>
Smily
- 1,990
- 2
- 10
- 29
0
Ansible's module git can do git archive but the problem is it does it from a local clone. If there is no local clone it clones first which is what you want to avoid so you cannot use module git.
Hence you have to use command or shell:
- name: Get a file using git archive
command: git archive --remote=https://bitbucket.com/user/project.git HEAD:path/in/repo filename -o /path/to/archive.zip
phd
- 69,888
- 11
- 97
- 133
-
To my knowledge, Bitbucket does not support the archive command, as it uses https and not git. – user228505 Feb 15 '21 at 21:59