From: Jay Soffian <jaysoffian@gmail.com>
To: Erik Iverson <iverson@biostat.wisc.edu>
Cc: git@vger.kernel.org
Subject: Re: simple git use case
Date: Thu, 5 Feb 2009 03:21:46 -0500 [thread overview]
Message-ID: <76718490902050021u5f53c94aq2f1c20c871c98f9c@mail.gmail.com> (raw)
In-Reply-To: <498A7073.4060206@biostat.wisc.edu>
On Wed, Feb 4, 2009 at 11:52 PM, Erik Iverson <iverson@biostat.wisc.edu> wrote:
> Dear all,
>
> I sincerely hope this is not an annoying question, I promise I have tried to
> do my homework here, but am stuck. My use case is simple. I have a desktop
> and a laptop. When I go on the trips, I'd love to be able to bring my
> "git-test" directory with me on the laptop, code some, and then get the new
> revisions back on the desktop when I get home (bonus if I can get the
> revisions back to my desktop over the internet while still on the road, in
> case, for example, my laptop gets stolen). No one else will be working on
> this stuff, it's strictly for me.
You may wish to read:
http://git.or.cz/gitwiki/GitFaq#head-b96f48bc9c925074be9f95c0fce69bcece5f6e73
(Why won't I see changes...)
and:
http://git.or.cz/gitwiki/GitFaq#push-is-reverse-of-fetch
(How would I use "git push"...)
> OK, so here's what I do.
>
> Desktop (dt):
>
> dt> cd git-test
> dt> git-init
> Initialized empty Git repository in /home/erik/projects/git-test/.git/
> dt> git add .
> dt> git-commit -am 'initial commit'
> Created initial commit c150815: initial commit
> 3 files changed, 14 insertions(+), 0 deletions(-)
> create mode 100644 test.R
> create mode 100644 test.sas
> create mode 100644 test.tex
>
> Looks good...
> Now over to the laptop (lt)!
>
> lt> git-clone ssh://myip/path/to/project
>
> And great, I have the three test.* files, looks good!
> So I make some changes to test.R on laptop, like I'm on the road. Then, on
> laptop:
>
> lt> git-commit -am 'an update'
>
> Looks good.
>
> Now I become a mouth-breather...and need some help :).
>
> My instinct was to git-push from the laptop,
>
> lt> git-push
>
> which succeeds
When you did the clone operation, you set things up such that the
branch called "master" on the desktop is replicated to a branch called
"origin/master" on the laptop. Whenever you do a "pull" on the laptop
(which clone did for you initially), it will do two things:
1) Fetch the latest master from desktop and store it as origin/master
on the laptop.
2) Merge origin/master (on the laptop) with master (again on the
laptop) and update your working copy with the result.
Now, whenever you do a "push" on the laptop, it is *not* a symmetrical
operation to fetch/merge. Rather, the push updates master on the
desktop to match master from the laptop. However, the working copy on
the desktop is not touched. So when you login to the desktop, you need
to manually refresh the working copy from what was pushed. You do this
with "git reset --hard master". But be careful, if you have made
changes on the desktop and not committed them, these changes will be
lost when you do the reset.
The FAQ entries above discuss two alternatives to make this safer. One
alternative updates the working copy automatically and mostly safely
via a hook, while the other alternative discusses making the "push"
from the laptop symmetrical to the "fetch".
I'll elaborate on the later alternative slightly. You could do your
clone like this:
lt> git-clone -o desktop ssh://myip/path/to/project
lt> git branch -a
* master
desktop/HEAD
desktop/master
The only difference is we've used "-o" so that we have a more
descriptive name for the desktop than "origin".
To make the push operation on the laptop symmetrical to the fetch
(remember, pull = fetch + merge), do this:
lt> git config remote.desktop.push "+refs/heads/*:refs/remotes/laptop/*"
Now take a look at .git/config and notice the fetch and push are symmetric:
[remote "desktop"]
url = ssh://myip/path/to/project
fetch = +refs/heads/*:refs/remotes/desktop/*
push = +refs/heads/*:refs/remotes/laptop/*
Let's do a commit and push it:
lt> echo bar > bar && git add bar && git commit -m "added bar"
lt> git push
To ssh://myip/path/to/project
* [new branch] master -> laptop/master
Back on the desktop:
dt> git branch -a
* master
laptop/master
Ah hah. So the changes have been pushed to laptop/master, but of
course, the working copy is not up-to-date. When can fix that with:
dt> git merge laptop/master
Updating 785a74b..09ab37d
Fast forward
bar | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 bar
This merges laptop/master into master, then updates the working copy
with the result. If you'd like "git pull" to be an alias for "git
merge laptop/master", you can:
dt> git config branch.master.remote .
dt> git config branch.master.merge refs/remotes/laptop/master
dt> git pull
From .
* remote branch laptop/master -> FETCH_HEAD
Already up-to-date.
j.
next prev parent reply other threads:[~2009-02-05 8:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-05 4:52 simple git use case Erik Iverson
2009-02-05 8:21 ` Jay Soffian [this message]
2009-02-05 14:57 ` Sitaram Chamarty
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=76718490902050021u5f53c94aq2f1c20c871c98f9c@mail.gmail.com \
--to=jaysoffian@gmail.com \
--cc=git@vger.kernel.org \
--cc=iverson@biostat.wisc.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).