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

Re: Rebase

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jan 19, 2025, 16:21 UTC
Message-ID
<Z40mlmfnUOXI2ghd@tapette.crustytoothpaste.net>
In-Reply-To
<CAODtcdcTjquNUBaTWKzyy54J5NoH7WO+9uMzJ+wWRDf0Na3OPA@mail.gmail.com>
On 2025-01-19 at 05:29:09, Al Grant wrote:
Show 15 quoted lines
> Hello,
> 
> I am looking for some assistance rebasing please.
> 
> I have a feature branch which has the many recent commits and a main
> branch which has not had a commit for a long time. I want to make the
> code in the feature branch the code in the main branch.
> 
> I think a rebase is the command I need, but the exact steps I am not sure of.
> 
> I did try this:
> 
> 1. Sync both branches with remote (github)
> 2. git checkout feature
> 3. git rebase main

If you just want to make the branches completely identical, you can do this:

---- $ git checkout feature $ git update-ref refs/heads/main $(git rev-parse --verify refs/heads/feature) ----

That will make `main` the exact same commit as `feature`. Note that you don't want to be on the destination branch (in this case, `main`) when you do the `git update-ref` call because that will result in the index being out of sync with the commit.

You could also do this:

---- $ git checkout main $ git reset --hard feature ----

That will update `main` and the working tree to be completely identical to `feature`. Please note that it will also completely and irrecoverably destroy changes in any modified files in the working tree, so you may prefer the first option, which is a little safer.

In either case, if there are changes in the `main` branch which are not in the `feature` branch, this will remove them. What I gave you above will make them completely identical in every way, including in terms of history.

If you want to preserve some of those changes, then you do need a rebase, and the commands you gave are correct. You will then need to resolve the merge conflicts in each conflicting commit and continue the rebase each time.

-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA
Previous: Al GrantNext: Al Grant
Message 2 of 6 in “Rebase”
  1. Al GrantJan 19, 2025
  2. brian m. carlsonJan 19, 2025
  3. Al GrantJan 19, 2025
  4. D. Ben KnobleJan 19, 2025
  5. brian m. carlsonJan 20, 2025
  6. Al GrantJan 20, 2025

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.