this post was submitted on 23 Oct 2023
1 points (100.0% liked)

Emacs

314 readers
2 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

When local repository moved ahead and remote also moved ahead, the remote doesn't allow Push. You have to first Pull. But sometimes pull doesn't work straight forward, you have to specify the merge strategy. This happens when `--ff-only` doesn't work for some reason.

In such a scenario, I normally use `--no-rebase` option. It creates a new commit with the merge. I can use `--rebase` also. But that is my personal preference. I want to keep the history of changes as is.

I couldn't find `--no-rebase` option in the Magit interface. Any idea, how to do that using Magit?

ChatGPT suggests that instead of direct Pull i.e. `F u`, I should first fetch and then merge i.e. `f u` followed by merging aka `m m`. Although, I haven't tried it yet. But just wanted to ask, if there is a direct way to achieve `--no-rebase` in Pull.

top 13 comments
sorted by: hot top controversial new old
[–] WallyMetropolis@alien.top 3 points 1 year ago (2 children)

I would also suggest fetch. Pull is fetch and merge. So if you don't want to merge, you can just fetch.

[–] hambungler67@alien.top 1 points 1 year ago (1 children)

You and chatgpt in unison...

[–] WallyMetropolis@alien.top 1 points 1 year ago

That's why I said 'also.'

[–] jangid@alien.top 1 points 1 year ago (1 children)

I am okay with this approach. I just wanted to make sure that I am not missing anything. Magit claims that it provides all the features that are normally available via CLI route. So I thought may be `git pull --no-rebase` is hidden somewhere in the user interface.

[–] WallyMetropolis@alien.top 1 points 1 year ago

That I cannot answer. Never used that flag. Maybe try grepping the magit package.

[–] pokkiff@lemmy.sdf.org 1 points 1 year ago

I avoid the need to do this by always keeping my local changes in a branch. Then I can pull master from the remote without any merging, rebase my branch, then merge the branch back into master in a fast forward. Keeps a clean stack of commits without any merges in the history.

[–] noooit@alien.top 1 points 1 year ago (2 children)

No rebase is the default for both magit and git

[–] troll-gpt@alien.top 1 points 1 year ago (1 children)

This. Git pull will never rebase unless told to do so.

[–] jangid@alien.top 1 points 1 year ago

I understand that. But we have to choose betweet --rebase, --no-rebase or --ff-only when git gets stuck.

[–] jangid@alien.top 1 points 1 year ago (2 children)

If Magit is functioning correctly, it shouldn't error out when both the remote and local repos have been updated post the last sync. Currently, to resolve this, I resort to the CLI and run git pull --no-rebase, which prompts for a comment and creates a new commit upon saving.

I want exactly this behavior inside Magit. Is there a setting to do that?

[–] troll-gpt@alien.top 1 points 1 year ago

You are doing something wrong and/or your understanding of git/magit is lacking. Pulling from a divergent remote branch is what we all do, every single day and Magit obviously covers this scenario, by default - without rebasing.

What happens after the magit error? are you in a merge situation? is magit waiting for you to resolve conflicts? if you press m are you asked to to complete or abort the merge?

[–] noooit@alien.top 1 points 1 year ago

It should error out in a such case and you should rebase your local changes from remote whenever you can, manually fixing the conflicts if they exist.

The only use case for no rebase is when you have a gitconfig not to rebase on pull and you manually want to just pull, which is a quite rare use case.

[–] accoil@alien.top 1 points 1 year ago

Could potentially add it to the pull interface:

  (transient-append-suffix 'magit-pull "-r" '("-R" "No rebase" "--no-rebase"))

(positions it under the rebase flag -r)