Re: simple git use case

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 4, 2009 at 11:52 PM, Erik Iverson <iverson@xxxxxxxxxxxxxxxx> 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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux