My goal is to clone/pull/whatever a copy of the latest version of a branch of my repository to my test web server, to test before production.
Note: I realize there are a ton of similar questions on here, but the ones I've looked into were different enough from my situation that I still came away a bit confused.
I am not very well-versed in git
on the command line (I tend to use GUI tools), so I'm not sure if I have this right. What I've got so far works, but the initial pull seemed pretty big, so I'm wondering if I am getting the whole history, or only the latest version.
I do not ever want to make changes live on the server or push back to origin. This only needs to be a one-way street.
Let's say I have a branch called test
, which is what I will load onto the test web server. However, we don't want the root directory of the repository, because there's some cruft in there. We only want the /sub
directory and everything below. The initial setup on my server:
$ cd ~/webapps/test_dir
$ git init
$ git remote add origin https://github.com/user/repository.git
$ git config core.sparseCheckout true
$ echo "sub/*" >> .git/info/sparse-checkout
Then each time I want to update the code on the server, this is what I will run:
$ git pull --depth=1 origin test
Is this command correct, to replace what's on the server with only the latest code, with no history? Is there a more efficient command to accomplish what I want?
Update
In light of Github's lack of support for git archive
(which seems like the way to go otherwise), I am trying to work up a solution getting an archive using their APIv3, which they suggested in a support email response.
I've gotten as far as getting a downloaded archive of the correct branch of my repo:
$ curl -L --user "username" https://api.github.com/repos/<username>/<reponame>/tarball/<branchname> > example.tar.gz
But that gets me everything from the root of the branch. What I really want is only one subfolder, but I have yet to figure out how to filter for that.
Update update
Got confirmation from GitHub that there is no way to retrieve a subfolder through this API method. So… back to the way I was doing it in the first place, I think.