{"thread":{"id":"20357","subject":"git for pushing local subdir to website","startedAt":"2009-08-03T17:11:13Z","lastAt":"2009-08-03T21:48:40Z","messageCount":6,"participants":["Matt Di Pasquale","Wesley J. Landaker"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"119414","messageId":"13f0168a0908031011odd98c03ye08a1b0774fca523@mail.gmail.com","threadId":"20357","inReplyTo":null,"subject":"git for pushing local subdir to website","fromName":"Matt Di Pasquale","fromEmail":"pasquale@fas.harvard.edu","sentAt":"2009-08-03T17:11:13Z","receivedAt":"2009-08-03T17:11:13Z","isPatch":false,"sender":{"key":"pasquale@fas.harvard.edu","avatar":null},"body":"I made a post here about this here:\nhttp://stackoverflow.com/questions/600079/is-there-any-way-to-clone-a-git-repositorys-sub-directory-only/1223407#1223407\n\nBasically, I'm working alone on a website (well, it's a facebook\napp.). What's the best way to sync my local copy with my production?\nbut i want the production to only be linked with the production subdir\nof my local project.\n\nso, I have a local copy i'm working on that I've organized like so.\ncall the project example. here are the dirs on my local comp. macbook.\n\nexample -extra [this holds files i don't want to go to the webserver\nmainly for security reasons. files like .psd files or .sql files. or\nreadme files. etc.] -example.com [this dir holds all the files i want\non my server for production at http://example.com]\n\ni have local git repo here: example/.git\n\nnow... how do i just push example.com and not extra and example.com?\n\ndo i need to make another git repo in example.com and make example.com\na submodule?\n\ni've also thought about using branches... a local branch and a\nproduction branch. but i only want one copy of the production files.\nbecause i want to be able to check out all the files and zip the dir\nand send it to someone to see.\n\nthat doesn't really make sense conceptually because example is one big\nproject. extra is like extra files and example.com is like what i\nreally want to go on web server...\n\nthanks!\n\n-matt\n"},{"id":"119419","messageId":"200908031201.41039.wjl@icecavern.net","threadId":"20357","inReplyTo":"13f0168a0908031011odd98c03ye08a1b0774fca523@mail.gmail.com","subject":"Re: git for pushing local subdir to website","fromName":"Wesley J. Landaker","fromEmail":"wjl@icecavern.net","sentAt":"2009-08-03T18:01:36Z","receivedAt":"2009-08-03T18:01:36Z","isPatch":false,"sender":{"key":"wjl@icecavern.net","avatar":"https://avatars.githubusercontent.com/u/67229?v=4"},"body":"On Monday 03 August 2009 11:11:13 Matt Di Pasquale wrote:\n> now... how do i just push example.com and not extra and example.com?\n[...]\n> that doesn't really make sense conceptually because example is one big\n> project. extra is like extra files and example.com is like what i\n> really want to go on web server...\n\nThere are several ways to do this with git, but since you are not going to \nmake commits on the server itself, have you considered simply pushing the \nproduction files you want with e.g. rsync?\n"},{"id":"119420","messageId":"13f0168a0908031109h10c02424l91938918639c6a57@mail.gmail.com","threadId":"20357","inReplyTo":"200908031201.41039.wjl@icecavern.net","subject":"Re: git for pushing local subdir to website","fromName":"Matt Di Pasquale","fromEmail":"pasquale@fas.harvard.edu","sentAt":"2009-08-03T18:09:26Z","receivedAt":"2009-08-03T18:09:26Z","isPatch":false,"sender":{"key":"pasquale@fas.harvard.edu","avatar":null},"body":"yes... i've thought of that. that's a good idea. i just love git and\ni've never really used rsync. how do i do that?\ni'll go google it..\ni guess it would also be nice to use git though incase i decide i want\na collaborator, right?\nhow would u set it up?\n-matt\n\nOn Mon, Aug 3, 2009 at 2:01 PM, Wesley J. Landaker<wjl@icecavern.net> wrote:\n> On Monday 03 August 2009 11:11:13 Matt Di Pasquale wrote:\n>> now... how do i just push example.com and not extra and example.com?\n> [...]\n>> that doesn't really make sense conceptually because example is one big\n>> project. extra is like extra files and example.com is like what i\n>> really want to go on web server...\n>\n> There are several ways to do this with git, but since you are not going to\n> make commits on the server itself, have you considered simply pushing the\n> production files you want with e.g. rsync?\n>\n"},{"id":"119425","messageId":"200908031258.13787.wjl@icecavern.net","threadId":"20357","inReplyTo":"13f0168a0908031109h10c02424l91938918639c6a57@mail.gmail.com","subject":"Re: git for pushing local subdir to website","fromName":"Wesley J. Landaker","fromEmail":"wjl@icecavern.net","sentAt":"2009-08-03T18:58:09Z","receivedAt":"2009-08-03T18:58:09Z","isPatch":false,"sender":{"key":"wjl@icecavern.net","avatar":"https://avatars.githubusercontent.com/u/67229?v=4"},"body":"On Monday 03 August 2009 12:09:26 Matt Di Pasquale wrote:\n> yes... i've thought of that. that's a good idea. i just love git and\n> i've never really used rsync. how do i do that?\n> i'll go google it..\n\nRsync can do a lot of things, but the usual easy way to do it is to do \nsomething like this to send files via rsync over an ssh connection:\n\nrsync -av /some_dir/ user@host:/some_dir/\n\nThis is essentially the same as using scp, but rsync saves a lot of network \nbandwidth by only sending the changes between the source and destination.\n\n> i guess it would also be nice to use git though incase i decide i want\n> a collaborator, right?\n\nSetting things up to have a collaboration is kind of orthogonal to \ninstalling a production version of your app, but you could use the same \nserver (and possibly the same git repository) for both things if you wanted \nto.\n\nHere an example of one way to do it:\n\nOn the server you could have a normal git repository in, say, \n/home/me/myapp, and it always has the \"production\" branch checked out. So \nnow the following directories are interesting:\n\n/home/me/myapp              -- repository branch w/ \"production\" checked out\n/home/me/myapp/.git         -- the actual bare git repository\n/home/me/myapp/example.com/ -- the files that the web server should see\n\nNow, you can use symlinks (or web-server configuration) to point the \nwebserver to the right locations, for example:\n\nhttp://example.com/myapp/     -- link to /home/me/myapp/example.com/\nhttp://example.com/myapp.git/ -- link to /home/me/myapp/.git/\n\nNow, collaborators can pull from the http://example.com/myapp.git and get \nthe whole project, but access to http://example.com/myapp/ sees the \nexample.com subdir as it's root, and everything works normally (assuming \nwebserver configuration & permissions are correct).\n\nNow you work on whatever branches you want, and push to the server whenever \nyou want for collaboration using whatever branches you want. As far as the \nwebserver is concerned, nothing changes when you do a push.\n\nThen, when you are ready to change the website, you put your production \nchanges on the \"production\" branch, push them, and make sure they are \nchecked out on the server (git push doesn't automatically check out the \nfiles), e.g.:\n\nclient$ # just made changes in production branch and want them \"live\"\nclient$ git push\n\nserver$ cd /home/me/myapp\nserver$ git reset --hard\n\n> how would u set it up?\n\nPersonally, I might set something like this if I had a good reason, but \notherwise, I'd host my git repository for collaboration separately, and just \nuse rsync to install production files on the server. For one thing, that \nneeds less prerequisites and setup on the server, so it's good if you don't \nfully control the server.\n\nEither way, a \"production\" branch is a good idea so you know logically \nexactly what and when you released things live.\n"},{"id":"119428","messageId":"13f0168a0908031213r59a9ea61m824ca7e5209962fc@mail.gmail.com","threadId":"20357","inReplyTo":"200908031258.13787.wjl@icecavern.net","subject":"Re: git for pushing local subdir to website","fromName":"Matt Di Pasquale","fromEmail":"pasquale@fas.harvard.edu","sentAt":"2009-08-03T19:13:43Z","receivedAt":"2009-08-03T19:13:43Z","isPatch":false,"sender":{"key":"pasquale@fas.harvard.edu","avatar":null},"body":"wow. thanks. that gave me some good ideas.\ni think u were right about rsync. it was pretty easy to set up.\nassuming the name of my app is myapp, i just put the following alias\nin my ~/.bash_profile on my local machine.\n\nalias mapush='rsync -e ssh -av --exclude=\".DS_Store\"\n~/Projects/myapp/myapp.com/\nmatt@mattdipasquale.com:projects/myapp.com/'\n\nbtw, is there a way to make aliases that are local to certain\ndirectories? like typing mapush works from any directory. what if i\njust wanted the alias to be push and only work from within\n~/Projects/myapp? is that possible?\n\nthose aren't the actual paths i used. but u get the point.\nthen i just type mapush and it does it.\n\nand i just use a local git repository in ~/Projects/myapp/.git to\ntrack local changes since none are made on the server... so i don't\nneed a git repo there like u said...\n\nit's pretty fast. but will rsync be okay if i decide to move files\naround a bit? i know git is pretty good about that. and what if i\ndelete certain files? will rsync delete them... like git does? guess\ni'll figure those questions out in time.\n\nthanks!\n\n-matt\n\n\nOn Mon, Aug 3, 2009 at 2:58 PM, Wesley J. Landaker<wjl@icecavern.net> wrote:\n> On Monday 03 August 2009 12:09:26 Matt Di Pasquale wrote:\n>> yes... i've thought of that. that's a good idea. i just love git and\n>> i've never really used rsync. how do i do that?\n>> i'll go google it..\n>\n> Rsync can do a lot of things, but the usual easy way to do it is to do\n> something like this to send files via rsync over an ssh connection:\n>\n> rsync -av /some_dir/ user@host:/some_dir/\n>\n> This is essentially the same as using scp, but rsync saves a lot of network\n> bandwidth by only sending the changes between the source and destination.\n>\n>> i guess it would also be nice to use git though incase i decide i want\n>> a collaborator, right?\n>\n> Setting things up to have a collaboration is kind of orthogonal to\n> installing a production version of your app, but you could use the same\n> server (and possibly the same git repository) for both things if you wanted\n> to.\n>\n> Here an example of one way to do it:\n>\n> On the server you could have a normal git repository in, say,\n> /home/me/myapp, and it always has the \"production\" branch checked out. So\n> now the following directories are interesting:\n>\n> /home/me/myapp              -- repository branch w/ \"production\" checked out\n> /home/me/myapp/.git         -- the actual bare git repository\n> /home/me/myapp/example.com/ -- the files that the web server should see\n>\n> Now, you can use symlinks (or web-server configuration) to point the\n> webserver to the right locations, for example:\n>\n> http://example.com/myapp/     -- link to /home/me/myapp/example.com/\n> http://example.com/myapp.git/ -- link to /home/me/myapp/.git/\n>\n> Now, collaborators can pull from the http://example.com/myapp.git and get\n> the whole project, but access to http://example.com/myapp/ sees the\n> example.com subdir as it's root, and everything works normally (assuming\n> webserver configuration & permissions are correct).\n>\n> Now you work on whatever branches you want, and push to the server whenever\n> you want for collaboration using whatever branches you want. As far as the\n> webserver is concerned, nothing changes when you do a push.\n>\n> Then, when you are ready to change the website, you put your production\n> changes on the \"production\" branch, push them, and make sure they are\n> checked out on the server (git push doesn't automatically check out the\n> files), e.g.:\n>\n> client$ # just made changes in production branch and want them \"live\"\n> client$ git push\n>\n> server$ cd /home/me/myapp\n> server$ git reset --hard\n>\n>> how would u set it up?\n>\n> Personally, I might set something like this if I had a good reason, but\n> otherwise, I'd host my git repository for collaboration separately, and just\n> use rsync to install production files on the server. For one thing, that\n> needs less prerequisites and setup on the server, so it's good if you don't\n> fully control the server.\n>\n> Either way, a \"production\" branch is a good idea so you know logically\n> exactly what and when you released things live.\n>\n"},{"id":"119432","messageId":"200908031548.45112.wjl@icecavern.net","threadId":"20357","inReplyTo":"13f0168a0908031213r59a9ea61m824ca7e5209962fc@mail.gmail.com","subject":"Re: git for pushing local subdir to website","fromName":"Wesley J. Landaker","fromEmail":"wjl@icecavern.net","sentAt":"2009-08-03T21:48:40Z","receivedAt":"2009-08-03T21:48:40Z","isPatch":false,"sender":{"key":"wjl@icecavern.net","avatar":"https://avatars.githubusercontent.com/u/67229?v=4"},"body":"On Monday 03 August 2009 13:13:43 Matt Di Pasquale wrote:\n> wow. thanks. that gave me some good ideas.\n> i think u were right about rsync. it was pretty easy to set up.\n> assuming the name of my app is myapp, i just put the following alias\n> in my ~/.bash_profile on my local machine.\n>\n> alias mapush='rsync -e ssh -av --exclude=\".DS_Store\"\n> ~/Projects/myapp/myapp.com/\n> matt@mattdipasquale.com:projects/myapp.com/'\n\nOkay, looks like you've got rsync figured out!\n\n> btw, is there a way to make aliases that are local to certain\n> directories? like typing mapush works from any directory. what if i\n> just wanted the alias to be push and only work from within\n> ~/Projects/myapp? is that possible?\n\nThe typical way to do this is to make a \"bin\" or \"scripts\" subdirectory of \nyour project, then make a shell script and call it via ./bin/push or \n./scripts/push or whatever. You can also do pretty much anything by using \nshell functions instead of aliases. They work just like shell aliases but \nare defined differently (man bash, then search for FUNCTIONS).\n\nSince the topic is git, I should also mention that you can also set up \nrepository hooks that make things happen when triggered, e.g. automatically \nrsync to the server when you commit to \"production\" for example. Do a man \ngithooks for more info on that.\n\n> it's pretty fast. but will rsync be okay if i decide to move files\n> around a bit? i know git is pretty good about that. and what if i\n> delete certain files? will rsync delete them... like git does? guess\n> i'll figure those questions out in time.\n\nRsync will not delete anything unless you add \"--delete\". If you use that, \nyou probably also want \"--delete-after\" for a website, which makes sure that \ndeletes are only done after everything else is copied over. The default is \nthe same as \"--delete-before\", which does deletes before copying things \n(e.g. to save disk space).\n\nAs far as raw network transfer performance, git and rsync are probably \npretty comparible, as they both are passing just changes instead of complete \nfiles around. Obviously they work very differently internally so e.g. I \nimagine that git will perform much better in some cases because it tracks \ncontent instead of files.\n"}]}