git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tait <git.git@t41t.com>
To: Thomas Anderson <zelnaga@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: a few beginner git questions
Date: Mon, 8 Mar 2010 10:55:05 -0800	[thread overview]
Message-ID: <20100308185505.GP2480@ece.pdx.edu> (raw)
In-Reply-To: <15b345f1003062102l22ac2d2fn3ed5b73221bf4216@mail.gmail.com>

> How, then, do I update code?  ie. I perform my initial clone, make
> some changes and commit / push them.  Someone else then comes along,
> makes some changes and commits them.  The next day, I do Remote ->
> Fetch from -> origin to update my code to the latest in Git but
> c:\git\test\clone\README is exactly the same as it was before.  How do
> I update the initial clone such that I can edit the updated files?

As Dmitry already said, you can either merge in the upstream changes,
or rebase your own changes on top of the upstream changes. I usually
rebase.

Here's my typical workflow. It may not be elegant, but it works well
for me. Hopefully it's useful for you, because understanding workflow
was one of the most intimidating parts of learning git for me.

git pull   # equivalent of git fetch + git merge
           # ... my local master is always clean; this is a fast-forward
git checkout -b exp_smoothing 
           # create a new branch to work
vi         # start making my intended changes
git add    # stage my changes
vi         # make some more changes I don't want to commit, like enabling 
           # debug, bypassing some uninteresting code, etc.
gcc        # oops, there were syntax errors
vi
git add    # to stage just the relevant fixes (or git add -p)
git commit # save my progress
run        # discover some things to fix
...        # repeat the bit from gcc to here many times over
run        # It works ..  maybe it's a few days since I started
           # By now, my history is an ugly mess
git rebase -i exp_smoothing^
           # I re-order, combine, and split commits
           # When I'm done, the history is neat and logical
git checkout master
           # switch back to master (which is still clean)
git pull origin
           # get any updates from the last couple days
           # there will be no conflicts; it's a fast-forward

My history looks like this:

               exp_smoothing branch
              |-- a <-- b <-- c <-- d
              v
master: Z <-- Y <-- X <-- W <-- V

Before switching back to master and doing pull, I only knew about Z
and Y, and in my own local repository, I added a, b, c, d, which are
the cleaned-up version of my exp_smoothing development. When I did
a git pull, I incorporated X, W, and V.

Picking up with the workflow again...

git checkout exp_smoothing
           # back to my work-in-progress branch
git rebase master
           # replay exp_smoothing on top of the new master (now 
           # at V instead of Y)
           # resolve conflicts, if X, W, V conflict with a, b, c, d

History is now:
                         exp_smoothing branch
                        |-- a' <-- b' <-- c' <-- d'
master:                 v
Z <-- Y <-- X <-- W <-- V

git checkout master
git merge exp_smoothing
           # because I resolved all the conflicts during the rebase
           # this should merge conflict-free, as a fast-forward.
git push origin
           # publish my changes (to master) for the rest of the world
git branch -d exp_smoothing
           # exp_smoothing is merged into master; no need to keep it 
           # around anymore

The last four steps occur very quickly. The final history is:

master: Z <-- Y <-- X <-- W <-- V <-- a' <-- b' <-- c' <-- d'

Given my workflow, why branch at all? Sometimes I may be working
on more than one branch at a time, or I may get interrupted on
exp_smoothing development to make a regression fix to master, or
maybe I discover that I don't want to merge exp_smoothing until the
next major version release. It's just easier to manage as a separate
branch up until the last four or six steps. I can rebase exp_smoothing
on top of master over and over again until I finally merge and publish
it.

Tait

  parent reply	other threads:[~2010-03-08 18:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-06  6:42 a few beginner git questions Thomas Anderson
2010-03-06  7:01 ` Allan Wind
2010-03-06  7:05 ` Tait
2010-03-07  2:23   ` Thomas Anderson
2010-03-07  9:08     ` Dmitry Potapov
2010-03-07  5:02   ` Thomas Anderson
2010-03-07  8:50     ` Dmitry Potapov
2010-03-08 18:55     ` Tait [this message]
2010-03-07  9:39 ` Junio C Hamano

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=20100308185505.GP2480@ece.pdx.edu \
    --to=git.git@t41t.com \
    --cc=git@vger.kernel.org \
    --cc=zelnaga@gmail.com \
    /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).