git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git rebase: yet another newbie quest.

From
Theodore Ts'o <tytso@mit.edu>
Date
Sep 5, 2014, 15:41 UTC
Message-ID
<20140905154159.GB1510@thunk.org>
In-Reply-To
<87a96ecqe9.fsf@osv.gnss.ru>

I'm not going to say what you *should* have done, since it's not clear whether anything close to what you were doing is a supported workflow. But I can tell you what I *do* myself. Personally, I vastly distrust git pull --rebase.

So in general, my pulls are all the equivalent of "git pull --ff-only", and if I want to rebase the topic branch (which in general, is a bad idea to do regularly; I will generally not do it at all until I'm almost done). So I'll branch the topic branch off of origin (which tracks origin/master, typically):

git checkout -b topic1 origin
<hack hack hack>
git commit
    .
    .
    .
Then I might do something like this to do a build:
git fetch origin ; git branch -f origin origin/master    # this is optional
git checkout -B build origin
git merge topic1
git merge topic2
    ...
<make>

In general, I will only rebase a topic branch when it's needed to fix a serious conflcit caused by significant changes upstream. And in that case, I might do something like this:

git checkout topic1 git rebase origin/master <make> <make check>

This basically goes to a philosophical question of whether it's simpler to tell users to use a single command, such as "git pull --rebase", or whether to tell users to use a 2 or 3 commands that conceptually much more simple. Personally, I type fast enough that I tend to use simple commands, and not try to use things like automated branch tracking. That way I don't have to strain my brain thinking about things like "fork points". :-)

OTOH, some people feel that it's better to make things like "git pull --rebase" work and do the right thing automatically, because <competing DSCM> allows you to do it in a single command. And indeed, if you use "git pull --rebase" without any topic branches, it works fine. But then when you start wanting to do things that are more complicated, the automated command starts getting actually harder and more confusing (at least in my opinion).

I don't know if a workflow involving topic branches was even expected to work with "git pull --rebase", and if so, how to set things up so that they do work smoothly. All I know is that the issue never arises with me, because it's rare that I use git pull, let alone git pull --rebase. That's because I usually like to take a quick look at what I've pulled (using gitk, or git log) before do the merge operation.

If I'm doing a pull from a repo that I control, and so I think I'm sure I know what's there, I might skip the "git fetch", and do a "git pull --ff-only" instead. But in general I prefer to do the merging separate from the pull operation.

Cheers,
						- Ted

P.S. There is a separate, and completely valid discussion which is how to prevent a newbie from falling into a same trap you did. I'll defer that discussion to others...

Previous: Sergey OrganovNext: Sergey Organov
Message 2 of 9 in “git rebase: yet another newbie quest.”
  1. Sergey OrganovSep 5, 2014
  2. Theodore Ts'oSep 5, 2014
  3. Sergey OrganovSep 8, 2014
  4. Theodore Ts'oSep 8, 2014
  5. Sergey OrganovSep 8, 2014
  6. Theodore Ts'oSep 8, 2014
  7. Sergey OrganovSep 8, 2014
  8. John KeepingSep 5, 2014
  9. Sergey OrganovSep 8, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.