Git development
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: Al Grant <bigal.nz@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Rebase
Date: Sun, 19 Jan 2025 16:21:42 +0000	[thread overview]
Message-ID: <Z40mlmfnUOXI2ghd@tapette.crustytoothpaste.net> (raw)
In-Reply-To: <CAODtcdcTjquNUBaTWKzyy54J5NoH7WO+9uMzJ+wWRDf0Na3OPA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1871 bytes --]

On 2025-01-19 at 05:29:09, Al Grant wrote:
> 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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

  reply	other threads:[~2025-01-19 16:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-19  5:29 Rebase Al Grant
2025-01-19 16:21 ` brian m. carlson [this message]
     [not found]   ` <CAODtcdf-+QpPpB5R-hLkKWKacwM=N3=XRDs-tK60W9WzUJu7xw@mail.gmail.com>
2025-01-19 20:39     ` Rebase Al Grant
2025-01-19 23:08       ` Rebase D. Ben Knoble
2025-01-20  1:32       ` Rebase brian m. carlson
2025-01-20 21:15         ` Rebase Al Grant

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=Z40mlmfnUOXI2ghd@tapette.crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=bigal.nz@gmail.com \
    --cc=git@vger.kernel.org \
    /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