{"thread":{"id":"17578","subject":"simple git use case","startedAt":"2009-02-05T04:52:03Z","lastAt":"2009-02-05T14:57:28Z","messageCount":3,"participants":["Erik Iverson","Jay Soffian","Sitaram Chamarty"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"103269","messageId":"498A7073.4060206@biostat.wisc.edu","threadId":"17578","inReplyTo":null,"subject":"simple git use case","fromName":"Erik Iverson","fromEmail":"iverson@biostat.wisc.edu","sentAt":"2009-02-05T04:52:03Z","receivedAt":"2009-02-05T04:52:03Z","isPatch":false,"sender":{"key":"iverson@biostat.wisc.edu","avatar":null},"body":"Dear all,\n\nI sincerely hope this is not an annoying question, I promise I have tried to do \nmy homework here, but am stuck.  My use case is simple.  I have a desktop and a \nlaptop.  When I go on the trips, I'd love to be able to bring my \"git-test\" \ndirectory with me on the laptop, code some, and then get the new revisions back \non the desktop when I get home (bonus if I can get the revisions back to my \ndesktop over the internet while still on the road, in case, for example, my \nlaptop gets stolen).  No one else will be working on this stuff, it's strictly \nfor me.\n\nOK, so here's what I do.\n\nDesktop (dt):\n\ndt> cd git-test\ndt> git-init\nInitialized empty Git repository in /home/erik/projects/git-test/.git/\ndt> git add .\ndt> git-commit -am 'initial commit'\nCreated initial commit c150815: initial commit\n  3 files changed, 14 insertions(+), 0 deletions(-)\n  create mode 100644 test.R\n  create mode 100644 test.sas\n  create mode 100644 test.tex\n\nLooks good...\nNow over to the laptop (lt)!\n\nlt> git-clone ssh://myip/path/to/project\n\nAnd great, I have the three test.* files, looks good!\nSo I make some changes to test.R on laptop, like I'm on the road. Then, on laptop:\n\nlt> git-commit -am 'an update'\n\nLooks good.\n\nNow I become a mouth-breather...and need some help :).\n\nMy instinct was to git-push from the laptop,\n\nlt> git-push\n\nwhich succeeds, but then a git-pull\nfrom desktop says:\n\ndt> git-pull\nfatal: 'origin': unable to chdir or not a git archive\nfatal: The remote end hung up unexpectedly\n\nOK, so look around mailing list archives...I try, without knowing what it means \nat all:\n\ndt> git-config branch.master.remote .\ndt> git-pull\n From .\n  * branch            HEAD       -> FETCH_HEAD\nAlready up-to-date.\n\nHmmm, so it did something, but not what I'd expect.  How about:\n\ndt> git-checkout\nM\ttest.R\n\nSo it realizes that file has been modified...\n\ndt> git-checkout -f\n\nThis gives no message of any type, and now I see my modified test.R file on my \ndesktop, so good! I'm happy with this, but I must know, it this the Right Way to \nuse git for my use case, or am I doing something silly?\n\nThank you for providing this software.\n\nBest Regards,\nErik Iverson\n"},{"id":"103304","messageId":"76718490902050021u5f53c94aq2f1c20c871c98f9c@mail.gmail.com","threadId":"17578","inReplyTo":"498A7073.4060206@biostat.wisc.edu","subject":"Re: simple git use case","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2009-02-05T08:21:46Z","receivedAt":"2009-02-05T08:21:46Z","isPatch":false,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Wed, Feb 4, 2009 at 11:52 PM, Erik Iverson <iverson@biostat.wisc.edu> wrote:\n> Dear all,\n>\n> I sincerely hope this is not an annoying question, I promise I have tried to\n> do my homework here, but am stuck.  My use case is simple.  I have a desktop\n> and a laptop.  When I go on the trips, I'd love to be able to bring my\n> \"git-test\" directory with me on the laptop, code some, and then get the new\n> revisions back on the desktop when I get home (bonus if I can get the\n> revisions back to my desktop over the internet while still on the road, in\n> case, for example, my laptop gets stolen).  No one else will be working on\n> this stuff, it's strictly for me.\n\nYou may wish to read:\n\n  http://git.or.cz/gitwiki/GitFaq#head-b96f48bc9c925074be9f95c0fce69bcece5f6e73\n  (Why won't I see changes...)\n\nand:\n\n  http://git.or.cz/gitwiki/GitFaq#push-is-reverse-of-fetch\n  (How would I use \"git push\"...)\n\n\n> OK, so here's what I do.\n>\n> Desktop (dt):\n>\n> dt> cd git-test\n> dt> git-init\n> Initialized empty Git repository in /home/erik/projects/git-test/.git/\n> dt> git add .\n> dt> git-commit -am 'initial commit'\n> Created initial commit c150815: initial commit\n>  3 files changed, 14 insertions(+), 0 deletions(-)\n>  create mode 100644 test.R\n>  create mode 100644 test.sas\n>  create mode 100644 test.tex\n>\n> Looks good...\n> Now over to the laptop (lt)!\n>\n> lt> git-clone ssh://myip/path/to/project\n>\n> And great, I have the three test.* files, looks good!\n> So I make some changes to test.R on laptop, like I'm on the road. Then, on\n> laptop:\n>\n> lt> git-commit -am 'an update'\n>\n> Looks good.\n>\n> Now I become a mouth-breather...and need some help :).\n>\n> My instinct was to git-push from the laptop,\n>\n> lt> git-push\n>\n> which succeeds\n\nWhen you did the clone operation, you set things up such that the\nbranch called \"master\" on the desktop is replicated to a branch called\n\"origin/master\" on the laptop. Whenever you do a \"pull\" on the laptop\n(which clone did for you initially), it will do two things:\n\n1) Fetch the latest master from desktop and store it as origin/master\non the laptop.\n2) Merge origin/master (on the laptop) with master (again on the\nlaptop) and update your working copy with the result.\n\nNow, whenever you do a \"push\" on the laptop, it is *not* a symmetrical\noperation to fetch/merge. Rather, the push updates master on the\ndesktop to match master from the laptop. However, the working copy on\nthe desktop is not touched. So when you login to the desktop, you need\nto manually refresh the working copy from what was pushed. You do this\nwith \"git reset --hard master\". But be careful, if you have made\nchanges on the desktop and not committed them, these changes will be\nlost when you do the reset.\n\nThe FAQ entries above discuss two alternatives to make this safer. One\nalternative updates the working copy automatically and mostly safely\nvia a hook, while the other alternative discusses making the \"push\"\nfrom the laptop symmetrical to the \"fetch\".\n\nI'll elaborate on the later alternative slightly. You could do your\nclone like this:\n\nlt> git-clone -o desktop ssh://myip/path/to/project\nlt> git branch -a\n* master\n  desktop/HEAD\n  desktop/master\n\nThe only difference is we've used \"-o\" so that we have a more\ndescriptive name for the desktop than \"origin\".\n\nTo make the push operation on the laptop symmetrical to the fetch\n(remember, pull = fetch + merge), do this:\n\nlt> git config remote.desktop.push \"+refs/heads/*:refs/remotes/laptop/*\"\n\nNow take a look at .git/config and notice the fetch and push are symmetric:\n\n[remote \"desktop\"]\n\turl = ssh://myip/path/to/project\n\tfetch = +refs/heads/*:refs/remotes/desktop/*\n\tpush = +refs/heads/*:refs/remotes/laptop/*\n\nLet's do a commit and push it:\n\nlt> echo bar > bar && git add bar && git commit -m \"added bar\"\nlt> git push\nTo ssh://myip/path/to/project\n * [new branch]      master -> laptop/master\n\nBack on the desktop:\n\ndt> git branch -a\n* master\n  laptop/master\n\nAh hah. So the changes have been pushed to laptop/master, but of\ncourse, the working copy is not up-to-date. When can fix that with:\n\ndt> git merge laptop/master\nUpdating 785a74b..09ab37d\nFast forward\n bar |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n create mode 100644 bar\n\nThis merges laptop/master into master, then updates the working copy\nwith the result. If you'd like \"git pull\" to be an alias for \"git\nmerge laptop/master\", you can:\n\ndt> git config branch.master.remote .\ndt> git config branch.master.merge refs/remotes/laptop/master\ndt> git pull\nFrom .\n * remote branch     laptop/master -> FETCH_HEAD\nAlready up-to-date.\n\nj.\n"},{"id":"103338","messageId":"slrngolvio.sjl.sitaramc@sitaramc.homelinux.net","threadId":"17578","inReplyTo":"76718490902050021u5f53c94aq2f1c20c871c98f9c@mail.gmail.com","subject":"Re: simple git use case","fromName":"Sitaram Chamarty","fromEmail":"sitaramc@gmail.com","sentAt":"2009-02-05T14:57:28Z","receivedAt":"2009-02-05T14:57:28Z","isPatch":false,"sender":{"key":"sitaramc@gmail.com","avatar":"https://avatars.githubusercontent.com/u/43316?v=4"},"body":"On 2009-02-05, Jay Soffian <jaysoffian@gmail.com> wrote:\n> On Wed, Feb 4, 2009 at 11:52 PM, Erik Iverson\n> <iverson@biostat.wisc.edu> wrote:\n>> and a laptop.  When I go on the trips, I'd love to be able to bring my\n>> \"git-test\" directory with me on the laptop, code some, and then get the new\n>> revisions back on the desktop when I get home (bonus if I can get the\n>> revisions back to my desktop over the internet while still on the road, in\n>> case, for example, my laptop gets stolen).  No one else will be working on\n>> this stuff, it's strictly for me.\n\nErik: I have the exact same situation, and I simply use a\nbare repository on the same desktop as a go-between.  I\nthink this is a better way of doing things -- gives you a\nlot of flexibility for all sorts of future situations\n(someone else joining the project, you having to temporarily\nuse a *third* machine, etc).\n\n> Now, whenever you do a \"push\" on the laptop, it is *not* a symmetrical\n> operation to fetch/merge. Rather, the push updates master on the\n> desktop to match master from the laptop. However, the working copy on\n> the desktop is not touched. So when you login to the desktop, you need\n> to manually refresh the working copy from what was pushed. You do this\n> with \"git reset --hard master\". But be careful, if you have made\n> changes on the desktop and not committed them, these changes will be\n> lost when you do the reset.\n\nIf you have a couple of minutes you may also want to take a\nlook at\nhttp://sitaramc.github.com/concepts-and-tips/0-terminology.html#a5\n, where I have explained *why* all this is necessary.  It\ndoesn't (but probably should) talk about how to set up a\nbare repo etc...\n\n[Git experts: be kind :-)  The site itself is a work in\nprogress, as is my knowledge of git.  However, that\nparticular page was written after that explanation and demo\nactually helped someone]\n"}]}