Benjamin
Benjamin

Reputation: 1183

Pull on a git repository after a rebase was made

My team mates love to git rebase while working on our project together. When i try to update a branch with a git pull after, it usually fails with merge conflicts.

So, to help myself, I tended to reset the branch with git reset --hard origin/... which doesn't seem to be a nice workflow.

What is the best approach to adapt the changes in the way it was meant to be?

Upvotes: 0

Views: 92

Answers (1)

Filip
Filip

Reputation: 23

It seems that your goal is to keep a linear commit history. What you could do is to fetch the remote changes on the branch and then rebase your local changes onto the remote changes.

You could use git pull --rebase to achieve that in one command by fetching the remote changes and rebasing your local changes onto them.

You might encounter merge conflicts, but after resolving these, you keep a linear commit history.

Below the line is a more detailed explanation.


The git pull --rebase command is a shortcut for the following:

I will assume the name of the branch is: master and the name of the remote is: origin.

You would first fetch the remote:

git fetch origin

Then you can rebase your local changes onto the remote changes. Run the following command while on the master branch:

git rebase origin/master

I would recommend watching the following explanation by Dan Gitschooldude (Can recommend the whole series):

https://www.youtube.com/watch?v=mzagfGeFUuA&list=PLu-nSsOS6FRIg52MWrd7C_qSnQp3ZoHwW&index=19

Upvotes: 1

Related Questions