1

I am new to the idea of git rebase, but I understand the purpose of it. Essentially if you are working on a feature branch new, and you want all the changes made to master reflected in your local branch, then git rebase is the way to go.

So I created my repo, with the general master branch.

I modified the README.md file and added one line. I committed and pushed.

Then I created a new branch called new.

Here I added two random files a and b, committed, and pushed.

Now I switched back to my master, and added another line to the README.md file. I committed and pushed.

So now, README.md on master looks like this:

line 1 data
line 2 data

On new, README.md looks like this:

line 1 data

and so in order to get it updated with master's README, I perform git rebase origin/master from the new branch.

Then git "rewinds" my work, and puts it on top of the line 2 data commit.

Now if I vim README.me, I see the same file as master.

What I want to happen now is I continue working on new, and nothing of a merge commit arises (image 2). What actually ends up happening is that git status says origin/new have diverged ... you have x and y different commits each ... use git pull.

I use git pull, and then a merge commit appears, which I must later push (image 1).

I don't want this "merge commit" because then the workflow looks like image 1 instead of image 2. How can I fix this?

enter image description here

enter image description here

K Split X
  • 2,181
  • 3
  • 11
  • 35

1 Answers1

1

git pull uses git merge under the hood. If you want it to rebase instead of merging, use git config --global pull.rebase true.

0x5453
  • 8,189
  • 22
  • 44
  • 1
    Or `git pull --rebase` for a one shot, see https://stackoverflow.com/a/13352008/8699120 – rkta Jul 15 '19 at 18:44