0

Say I pull the mainline of a repo, make some changes, added one commit my_commit. At the same time, someone else pushed someone_commit to remote mainline. Now if I want to push, if I do git pull, there will be conflicts and I have to add a merge commit. Is there a way I could achieve something like previous_commits->someone_commit->my_commit instead of `

previous_commits->someone_commit -> merge commits of ... ->my_commit -> 

1 Answer 1

1

Yes, this is the purpose of git rebase.

Something like:

git rebase origin/mainline 

This will reset your branch to mainline (with previous_commits at the tip), then replay your commits on top.

You will be prompted to resolve conflicts if there are any.


The following doesn't sound relevant to your current situation, but note that this will change the history of your local branch. If you have already pushed your local commits to a development branch, you will need to use a force push to rewrite the history on the remote development branch. But if, as you say, you and a colleague are working on the same branch, then this isn't likely to be a problem (and a force push on a shared branch can cause major issues)

Sign up to request clarification or add additional context in comments.

2 Comments

So my current commit has HEAD->mainline which is one commit ahead from origin/mainline locally. My local origin/mainline is on commit behind remote. In this way git rebase origin/mainline doesn't seem to work?
Try git fetch. This should pull the origin's commits in your origin/mainline branch. (I'm assuming mainline is a branch name)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.