Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rebasing a local branch from develop

Tags:

I want to rebase a feature branch from develop. I am using PhpStorm Git integration and I have 2 different develop branches:

refs/remotes/origin/develop refs/heads/develop 

In order to do not mess up things, which one do I have to choose to rebase?

like image 806
Kaiser Soze Avatar asked Jun 07 '18 08:06

Kaiser Soze


People also ask

Can we rebase a branch?

Luckily, using git reflog you can get the reflog of the remote branch. On the remote branch's reflog you can find a ref before it was rebased. You can then rebase your branch against that remote ref using the --onto option as discussed above in the Advanced Rebase Application section.

What happens when you rebase a branch?

The Rebase Option This moves the entire feature branch to begin on the tip of the main branch, effectively incorporating all of the new commits in main . But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch.


2 Answers

I don't know the phpstorm interface for Git, but in the command line I'd do the following:

  • git checkout develop
  • git pull origin develop -> this fetches the remote version of the develop branch and merges it (or rebases it, depending on your pull strategy) into/onto your local branch. This way the local and the remote versions of develop are the same
  • git checkout feature-brach
  • git rebase develop

If there are any conflicts - resolve them. After that you can create a pull request against develop.

like image 59
Alexander Popov Avatar answered Oct 29 '22 15:10

Alexander Popov


When you are at your branch, where you have committed changes: Do the following:

  1. git fetch
  2. git rebase origin/develop In case of any conflicts, please fix them. Then,
  3. git add .
  4. git rebase --continue
like image 39
Steven Avatar answered Oct 29 '22 14:10

Steven